Created
June 17, 2013 09:56
-
-
Save psihy/5795865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dmd 2.063 | |
// ref. http://d.hatena.ne.jp/yutakikuchi/20130617/1371425713 | |
import std.array, std.conv, std.datetime; | |
import std.stdio; | |
void main() { | |
// 現在時刻のDateTimeを取得 | |
{ | |
const current = Clock.currTime; | |
const datetime = current.toISOExtString.replace("T", " ").split(".").front; | |
writeln(datetime); // e.g. 2013-06-15 12:00:00 | |
} | |
// 現在時刻のTimeStampを取得 | |
{ | |
const current = Clock.currTime; | |
const timestamp = current.toUnixTime; | |
writeln(timestamp); // e.g. 1371265200 | |
} | |
// TimeStampからDateTimeへ変換 | |
{ | |
const timestamp = 1371265200; | |
const datetime = SysTime(unixTimeToStdTime(timestamp)).toISOExtString.replace("T", " ").split(".").front; | |
writeln(datetime); // 2013-06-15 12:00:00 | |
} | |
// DateTimeからTimeStampへ変換 | |
{ | |
const datetime = "2013-06-15 12:00:00"; | |
const timestamp = SysTime.fromISOExtString(datetime.replace(" ", "T")).toUnixTime; | |
writeln(timestamp); // 1371265200 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment