std.time

Module entries: Stopwatch, Time

class Stopwatch

This class allows measuring time taken by some task.

The stopwatch starts out stopped.

this()

this()

Instantiate the class.

stopped()

bool stopped()

True if the stopwatch is stopped.

seconds()

float seconds()

The number of seconds accumulated on the stopwatch. Note that the stopwatch must be stopped to access this property.

reset()

void reset()

Reset the stopwatch to its initial state.

start()

void start()

Start the stopwatch.

stop()

void stop()

Stop the stopwatch.

split()

Stopwatch split()

Split and reset the stopwatch.

This method returns another stopwatch stopped at the previous time. If the stopwatch is still running, by the time it is stopped, the sum of the returned stopwatch’s seconds and this one’s will be the same as if the stopwatch had not been split.

So this function allows atomically taking a “checkpoint” of the stopwatch.

class Time

This type describes a time without a timezone.

Example:

import std.stdio : print;
print("The current time is $(Time.now)");
secondsSince(other)

float secondsSince(Time other)

The number of fractional seconds from another time to this one.

now()

Time now()

The current time in the system timezone.

monotonic()

Time monotonic()

year()

int year()

Four-digit year, ie. “2003”

month()

int month()

One-base month

day()

int day()

One-base day

hour()

int hour()

Zero-base hour

minute()

int minute()

Zero-base minute

second()

int second()

Zero-base seconds

millisecond()

int millisecond()

Zero-base milliseconds

toString()

string toString()