Comment detail
文字列型日時ののN秒後時間取得 (Nested Flatten)使用例も書かないとダメですね。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import std.conv;
import std.date;
import std.stdio;
string DateEx(string datetime, int tdelta_in_secs)
{
d_time t = std.date.parse(datetime);
d_time new_datetime = t + tdelta_in_secs * std.date.TicksPerSecond;
return std.date.toString(new_datetime);
}
unittest {
assert(DateEx("Mon Sep 01 13:00:00 GMT+0900 2008", -3600) ==
"Mon Sep 01 12:00:00 GMT+0900 2008");
assert(DateEx("Mon Sep 01 13:00:00 GMT+0900 2008", 3600) ==
"Mon Sep 01 14:00:00 GMT+0900 2008");
}
void main(string[] args)
{
string datetime;
int tdelta_in_secs;
if (args.length == 3) {
datetime = args[1];
tdelta_in_secs = toInt(args[2]);
}
else {
d_time now = std.date.getUTCtime;
datetime = std.date.toString(now);
tdelta_in_secs = toInt(args[1]);
}
writefln("%s", DateEx(datetime, tdelta_in_secs));
}
// eof
|



Dubhead #7520() [ D ] Rating0/0=0.00
see:
Rating0/0=0.00-0+
1 reply [ reply ]