public class DateTime extends Object
Represents a date and time, including timezone information.
This class provides methods to create and manipulate date/time values. It supports initialization from a timestamp or from individual date/time components. DateTime is a reference type: a variable may contain null to represent an absent date, and assignments retain the same object reference.
import klyn.time dt = DateTime(year=2023, month=10, day=5, hour=14, minute=30, second=45) print(dt.toString()) # 2023-10-05 14:30:45 missing as DateTime = null assert missing is null
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | dayday as Int |
Day component. |
| public readonly property | dayOfWeekdayOfWeek as Int |
Returns the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday). |
| public readonly property | dayOfYeardayOfYear as Int |
Returns the day of the year (1..366). |
| public readonly property | hourhour as Int |
Hour component. |
| public readonly property | minuteminute as Int |
Minute component. |
| public readonly property | monthmonth as Int |
Month component (1..12). |
| public static readonly property | nownow as DateTime |
Returns the current date and time in the operating system's local timezone. |
| public static readonly property | nowUTCnowUTC as DateTime |
Returns the current date and time in UTC. |
| public readonly property | secondsecond as Int |
Second component. |
| public readonly property | timeZonetimeZone as TimeZone |
Timezone of this date/time. |
| public readonly property | timestamptimestamp as Timestamp |
Returns the timestamp representation of this DateTime object. |
| public readonly property | totalSecondstotalSeconds as Double |
Seconds since the Unix epoch, without creating a Timestamp wrapper. |
| public readonly property | usecondusecond as Int |
Microsecond component. |
| public readonly property | yearyear as Int |
Year component. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | DateTime | Constructs a DateTime from an epoch timestamp expressed in seconds. |
| public | DateTime | Constructs a DateTime by parsing a complete ISO 8601 date-time string. |
| public | DateTime | Constructs a DateTime from a timestamp. |
| public | DateTime | Constructs a DateTime from individual date/time components. |
| Modifier and Type | Member | Description |
|---|---|---|
| public override | toStringtoString() as String |
Returns a string representation of this DateTime object using the default locale. |
| public | toString | Returns a string representation using a custom format and the default locale. |
| public | toString | Returns a string representation of this DateTime object using a specific locale. |
| Modifier and Type | Member | Description |
|---|---|---|
| public static | operator+(dt as DateTime, duration as Duration) as DateTime | Adds a duration to this DateTime object. |
| public static | operator-(dt as DateTime, duration as Duration) as DateTime | Subtracts a duration from this DateTime object. |
| public static | operator-(left as DateTime, right as DateTime) as Duration | Subtracts one DateTime object from another. |