Datetime Type
日期时间类型
日期时间类型用于存储自1970年1月1日以来经过的秒数。这种类型占用8字节的内存。
日期时间的常量可以表示为字面字符串,由6部分组成,分别表示年份、月份、日期(或日期、月份、年份)、小时、分钟和秒的数值。常量用单引号括起来,并以“D”字符开头。
数值范围从1970年1月1日到3000年12月31日。可以省略日期(年、月、日)或时间(小时、分钟、秒),或者同时省略两者。
对于字面日期指定,建议明确指定年份、月份和日期。否则,编译器会返回警告关于不完整输入的问题。
示例:
datetime NY=D'2015.01.01 00:00'; // Time of beginning of year 2015
datetime d1=D'1980.07.19 12:30:27'; // Year Month Day Hours Minutes Seconds
datetime d2=D'19.07.1980 12:30:27'; // Equal to D'1980.07.19 12:30:27';
datetime d3=D'19.07.1980 12'; // Equal to D'1980.07.19 12:00:00'
datetime d4=D'01.01.2004'; // Equal to D'01.01.2004 00:00:00'
datetime compilation_date=__DATE__; // Compilation date
datetime compilation_date_time=__DATETIME__; // Compilation date and time
datetime compilation_time=__DATETIME__-__DATE__;// Compilation time
//--- Examples of declarations after which compiler warnings will be returned
datetime warning1=D'12:30:27'; // Equal to D'[date of compilation] 12:30:27'
datetime warning2=D''; // Equal to __DATETIME__
日期时间类型的字符串表示取决于编译模式:
datetime date=D'2014.03.05 15:46:58';
string str="mydate="+date;
//--- str="mydate=1394034418" - without #property strict
//--- str="mydate=2014.03.05 15:46:58" - with #property strict
另请参阅
最后更新于