Sul*_*man 2 datetime casting d
我需要将DateTime类型转换为Date.这是我的代码:
DateTime dt = DateTime(2015, 1, 1, 14, 10, 13);
Date z = cast(Date)dt;
Run Code Online (Sandbox Code Playgroud)
Error: cannot cast from DateTime to Date
怎么了?
DateTime不是Date,你不能投它.要转换,只需访问该DateTime.date()属性:
http://dlang.org/phobos/std_datetime.html#.DateTime.date
const pure nothrow @property @safe Date date();
Run Code Online (Sandbox Code Playgroud)The date portion of DateTime.
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |