The OpenD Programming Language

std.datetime

Phobos provides the following functionality for time:

FunctionalitySymbols
Points in TimeClock  Date  TimeOfDay  DateTime  SysTime 
TimezonesTimeZone  UTC  LocalTime  PosixTimeZone  WindowsTimeZone  SimpleTimeZone 
Intervals and Ranges of TimeInterval  PosInfInterval  NegInfInterval 
Durations of TimeDuration  weeks  days  hours  minutes  seconds  msecs  usecs  hnsecs  nsecs 
Time Measurement and BenchmarkingMonoTime  StopWatch  benchmark 

This functionality is separated into the following modules:

Modules

date
module std.datetime.date
interval
module std.datetime.interval
stopwatch
module std.datetime.stopwatch

Module containing some basic benchmarking and timing functionality.

systime
module std.datetime.systime
timezone
module std.datetime.timezone

Public Imports

core.time
public import core.time;
Undocumented in source.
std.datetime.date
public import std.datetime.date;
Undocumented in source.
std.datetime.interval
public import std.datetime.interval;
Undocumented in source.
std.datetime.systime
public import std.datetime.systime;
Undocumented in source.
std.datetime.timezone
public import std.datetime.timezone;
Undocumented in source.

Examples

Get the current time from the system clock.

import std.datetime.systime : SysTime, Clock;

SysTime currentTime = Clock.currTime();

Construct a specific point in time without timezone information and get its ISO string.

import std.datetime.date : DateTime;

auto dt = DateTime(2018, 1, 1, 12, 30, 10);
assert(dt.toISOString() == "20180101T123010");
assert(dt.toISOExtString() == "2018-01-01T12:30:10");

Construct a specific point in time in the UTC timezone and add two days.

import std.datetime.systime : SysTime;
import std.datetime.timezone : UTC;
import core.time : days;

auto st = SysTime(DateTime(2018, 1, 1, 12, 30, 10), UTC());
assert(st.toISOExtString() == "2018-01-01T12:30:10Z");
st += 2.days;
assert(st.toISOExtString() == "2018-01-03T12:30:10Z");

See Also

Meta

Authors

Jonathan M Davis and Kato Shoichi