Difference between revisions of "Useful D snippets"

From D Wiki
Jump to: navigation, search
(Created page with " http://dlang.org/intro-to-datetime.html import std.datetime; import core.stdc.time; void main() { time_t unixTime = core.stdc.time.time(null); auto stdTime =...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
+
==Converting a time_t unix timestamp into std.datetime types==
 
http://dlang.org/intro-to-datetime.html
 
http://dlang.org/intro-to-datetime.html
  
 +
<source lang="D">
 
import std.datetime;
 
import std.datetime;
 
import core.stdc.time;
 
import core.stdc.time;
 
void main() {
 
void main() {
        time_t unixTime = core.stdc.time.time(null);
+
    time_t unixTime = core.stdc.time.time(null);
        auto stdTime = unixTimeToStdTime(unixTime);
+
    auto stdTime = unixTimeToStdTime(unixTime);
        auto st = SysTime(stdTime);
+
    auto st = SysTime(stdTime);
 
}
 
}
 +
</source>
 +
 +
[[Category:CommonIdiom]]

Latest revision as of 19:50, 8 September 2015

Converting a time_t unix timestamp into std.datetime types

http://dlang.org/intro-to-datetime.html

import std.datetime;
import core.stdc.time;
void main() {
    time_t unixTime = core.stdc.time.time(null);
    auto stdTime = unixTimeToStdTime(unixTime);
    auto st = SysTime(stdTime);
}