The time
package contains functionality for working with time and date information.
The DateTime
struct is used to represent date and time data. See DateTime
.
Retrieves the current hour of the day (0 to 23).
Returns
Type | Description |
---|---|
Integer |
The current hour. |
Retrieves the current minute of the hour (0 to 59).
Returns
Type | Description |
---|---|
Integer |
The current minute. |
Retrieves the current second of the minute (0 to 60).
Returns
Type | Description |
---|---|
Integer |
The current second. |
Retrieves the time of day designation for 12-hour clocks as "AM" or "PM".
Returns
Type | Description |
---|---|
String |
"AM" or "PM". |
Format a DateTime
object as a string using a given format.
Parameters
Type | Name | Description |
---|---|---|
DateTime |
_datetime |
The DateTime object. |
String |
_format |
The format string. |
Returns
Type | Description |
---|---|
String |
The formatted value from a DateTime object. |
Retrieves the current timestamp formatted as "YYYY/mm/dd hh:mm:ss tt".
Returns
Type | Description |
---|---|
String |
The current timestamp formatted as "YYYY/mm/dd hh:mm:ss tt". |
Get current timestamp with a specific format.
Currently available format specifiers:
%Y
: Year with century as a decimal number (e.g.,2023
).%m
: Month as a zero-padded decimal number (e.g.,01
to12
).%d
: Day of the month as a zero-padded decimal number (e.g.,01
to31
).%H
: Hour (24-hour clock) as a zero-padded decimal number (e.g.,00
to23
).%M
: Minute as a zero-padded decimal number (e.g.,00
to59
).%S
: Second as a zero-padded decimal number (e.g.,00
to60
).
Additional specifiers:
%y
: Year without century as a zero-padded decimal number (e.g.,00
to99
).%b
or%h
: Abbreviated month name (e.g.,Jan
,Feb
,Mar
, ...).%B
: Full month name (e.g.,January
,February
,March
, ...).%a
: Abbreviated weekday name (e.g.,Sun
,Mon
,Tue
, ...).%A
: Full weekday name (e.g.,Sunday
,Monday
,Tuesday
, ...).%I
: Hour (12-hour clock) as a zero-padded decimal number (e.g.,01
to12
).%p
: Locale's equivalent of either AM or PM.%j
: Day of the year as a zero-padded decimal number (e.g.,001
to366
).%U
: Week number of the year (Sunday as the first day of the week) as a zero-padded decimal number (e.g.,00
to53
).%W
: Week number of the year (Monday as the first day of the week) as a zero-padded decimal number (e.g.,00
to53
).%c
: Locale's appropriate date and time representation.%x
: Locale's appropriate date representation.%X
: Locale's appropriate time representation.%Z
: Time zone name or abbreviation (no characters if no time zone exists).%z
: UTC offset in the form±HHMM
(e.g.,-0400
,+0230
).
Parameters
Type | Name | Description |
---|---|---|
String |
_format |
The format. |
Returns
Type | Description |
---|---|
String |
The current timestamp formatted as specified. |
Retrieves the day of the month (1 to 31).
Returns
Type | Description |
---|---|
Integer |
The current day of the month. |
Retrieves the current month of the year (1 to 12).
Returns
Type | Description |
---|---|
Integer |
The current month. |
Retrieves the current year.
Returns
Type | Description |
---|---|
Integer |
The current year. |
Retrieves the day of the week (1 to 7, where 1 is Sunday and 7 is Saturday).
Returns
Type | Description |
---|---|
Integer |
The day of the week. |
Retrieves the day of the year (0 to 365). December 31st is 364 on leap years.
Returns
Type | Description |
---|---|
Integer |
The day of the year. |
Checks whether it is currently Daylight Savings Time.
Returns
Type | Description |
---|---|
Boolean |
Indicates DST status. |
Check if a given year is a leap year.
Parameters
Type | Name | Description |
---|---|---|
Integer |
_year |
The year to check. |
Returns
Type | Description |
---|---|
Boolean |
Returns true if the given year is a leap year. |
Get the number of days in a given month. Requires the year for leap year checks.
Parameters
Type | Name | Description |
---|---|---|
Integer |
_year |
The year to check. |
Integer |
_month |
The month to check. |
Returns
Type | Description |
---|---|
Integer |
Returns the number of days in a given month. |
Retrieves the number of milliseconds since January 1st, 1970.
Returns
Type | Description |
---|---|
Float |
The milliseconds since the epoch. |
Retrieves the number of nanoseconds since January 1st, 1970.
Returns
Type | Description |
---|---|
Float |
The nanoseconds since the epoch. |
Converts ticks to milliseconds.
Returns
Type | Description |
---|---|
Float |
The ticks in milliseconds. |
Pauses execution for a specified duration in milliseconds.
Parameters
Type | Name | Description |
---|---|---|
Integer |
_ms |
The duration to sleep in milliseconds. |
Returns
Type | Description |
---|---|
Float |
The duration slept in milliseconds. |