View source code
Display the source code in std/datetime/package.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Module std.datetime

Phobos provides the following functionality for time:

Functionality Symbols
Points in Time Date  TimeOfDay  DateTime  SysTime 
Timezones TimeZone  UTC  LocalTime  PosixTimeZone  WindowsTimeZone  SimpleTimeZone 
Intervals and Ranges of Time Interval  PosInfInterval  NegInfInterval 
Durations of Time Duration  weeks  days  hours  minutes  seconds  msecs  usecs  hnsecs  nsecs 
Time Measurement and Benchmarking MonoTime  StopWatch  benchmark 

This functionality is separated into the following modules

See Also

Introduction to std.datetime
ISO 8601
Wikipedia entry on TZ Database
List of Time Zones

Example

Get the current time from the system clock

import std.datetime.systime : SysTime, Clock;

SysTime currentTime = Clock.currTime();

Example

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);
writeln(dt.toISOString()); // "20180101T123010"
writeln(dt.toISOExtString()); // "2018-01-01T12:30:10"

Example

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());
writeln(st.toISOExtString()); // "2018-01-01T12:30:10Z"
st += 2.days;
writeln(st.toISOExtString()); // "2018-01-03T12:30:10Z"

Functions

NameDescription
benchmark(n) The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. See benchmark. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.
comparingBenchmark() The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. Note that comparingBenchmark has not been ported over, because it's a trivial wrapper around benchmark. See benchmark. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.
measureTime() The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. Note that measureTime has not been ported over, because it's a trivial wrapper around StopWatch. See StopWatch. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.

Structs

NameDescription
ComparingBenchmarkResult The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. Note that comparingBenchmark has not been ported over, because it's a trivial wrapper around benchmark. See benchmark. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.
StopWatch The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. See StopWatch. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.

Aliases

NameTypeDescription
AutoStart Flag!("autoStart") The old benchmarking functionality in std.datetime (which uses TickDuration) has been deprecated. Use what's in std.datetime.stopwatch instead. It uses MonoTime and Duration. See AutoStart. This symbol will be removed from the documentation in October 2018 and fully removed from Phobos in October 2019.

Authors

Jonathan M Davis and Kato Shoichi

License

Boost License 1.0.