D:将日期时间转换为日期:无法从日期时间转换为日期
D: Converting DateTime to Date: cannot cast from DateTime to Date
我需要将 DateTime 类型转换为 Date。这是我的代码:
DateTime dt = DateTime(2015, 1, 1, 14, 10, 13);
Date z = cast(Date)dt;
Error: cannot cast from DateTime to Date
怎么了?
DateTime 不是日期,您不能强制转换它。要转换,只需访问 DateTime.date()
属性:
http://dlang.org/phobos/std_datetime.html#.DateTime.date
const pure nothrow @property @safe Date date();
The date portion of DateTime.
我需要将 DateTime 类型转换为 Date。这是我的代码:
DateTime dt = DateTime(2015, 1, 1, 14, 10, 13);
Date z = cast(Date)dt;
Error: cannot cast from DateTime to Date
怎么了?
DateTime 不是日期,您不能强制转换它。要转换,只需访问 DateTime.date()
属性:
http://dlang.org/phobos/std_datetime.html#.DateTime.date
const pure nothrow @property @safe Date date();
The date portion of DateTime.