Time & Timers

Overview

This section describes types and facilities for date, time and timer management. More…

import "sys_Timer.jnc"

// classes

class sys.Timer;

// global functions

void sys.sleep(uint32_t timeout);
uint64_t sys.getTimestamp();
uint64_t sys.getPreciseTimestamp();

string_t sys.formatTimestamp(
    uint64_t timestamp,
    string_t format
);

string_t sys.formatTimestamp(
    uint64_t timestamp,
    int timeZone,
    string_t format
);

Detailed Documentation

This section describes types and facilities for date, time and timer management.

Global Functions

void sys.sleep(uint32_t timeout)

Suspends the execution of the calling thread until timeout interval elapses. timeout is expressed in milliseconds.

uint64_t sys.getTimestamp()

Returns current system timestamp. Timestamp is expressed as a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

This format is the same as used in Windows FILETIME struct.

Even though nominally this timestamp is expressed as the number of 100-nanosecond intervals, a sub-microsecond precision is not guaranteed. For a guaranteed sub-microsecond precision, use sys.getPreciseTimestamp.

See also:

sys.getPreciseTimestamp

uint64_t sys.getPreciseTimestamp()

Returns current system high-precision timestamp. Timestamp is expressed as a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

This format is the same as used in Windows FILETIME struct.

This timestamp is guaranteed to have sub-microsecond precision. If you don’t need sub-microsecond precision, use a slightly faster sys.getTimestamp.

See also:

sys.getTimestamp

string_t sys.formatTimestamp(
    uint64_t timestamp,
    string_t format
)

string_t sys.formatTimestamp(
    uint64_t timestamp,
    int timeZone,
    string_t format
)

Returns string representation of the timestamp.

Format Specifiers:

Specifier

Output

%h

hour in 24-hour format (00..24)

%H

hour in 12-hour format (1..12)

%m

minutes (00..59)

%s

seconds (00..59)

%l

milliseconds (0..999)

%c

microseconds (0..999)

%p

AM / PM designition lower case (a / p)

%p

AM / PM designition upper case (A / P)

%y

year, last 2-digit format (0..99)

%Y

year, all digits

%D

day of month, leading zero (01..31)

%d

day of month, no leading zero (1..31)

%M

month index, leading zero (01..12)

%o

month index, no leading zero (1..12)

%n

month short name (Jan..Dec)

%N

month full name (January..December)

%w

week day short name (Sun..Sat)

%W

week day full name (Sunday..Saturday)

Example:

uint64_t ts = sys.getTimestamp();
print($"time: %1\n"(sys.formatTypestamp(ts, "%h:%m:%s.%l")));

See also:

sys.getTimestamp, sys.getPreciseTimestamp