D:将DateTime转换为Date:无法从DateTime转换为Date

时间:2015-02-21 05:54:56

标签: datetime casting d

我需要将DateTime类型转换为Date。这是我的代码:

DateTime dt = DateTime(2015, 1, 1, 14, 10, 13);
Date z = cast(Date)dt;

Error: cannot cast from DateTime to Date

怎么了?

1 个答案:

答案 0 :(得分:5)

DateTime不是日期,你不能施展它。要进行转换,只需访问DateTime.date()属性:

http://dlang.org/phobos/std_datetime.html#.DateTime.date

  

const pure nothrow @property @safe Date date();

The date portion of DateTime.