DateTime
classin packageklyn.time
public class DateTime extends Object
└ DateTime

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
Properties
Modifier and Type Member Description
public readonly property day
day as Int
Day component.
public readonly property dayOfWeek
dayOfWeek as Int
Returns the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
public readonly property dayOfYear
dayOfYear as Int
Returns the day of the year (1..366).
public readonly property hour
hour as Int
Hour component.
public readonly property minute
minute as Int
Minute component.
public readonly property month
month as Int
Month component (1..12).
public static readonly property now
now as DateTime
Returns the current date and time in the operating system's local timezone.
public static readonly property nowUTC
nowUTC as DateTime
Returns the current date and time in UTC.
public readonly property second
second as Int
Second component.
public readonly property timeZone
timeZone as TimeZone
Timezone of this date/time.
public readonly property timestamp
timestamp as Timestamp
Returns the timestamp representation of this DateTime object.
public readonly property totalSeconds
totalSeconds as Double
Seconds since the Unix epoch, without creating a Timestamp wrapper.
public readonly property usecond
usecond as Int
Microsecond component.
public readonly property year
year as Int
Year component.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public DateTime
DateTime(epochSeconds as Double, timeZone as TimeZone = TimeZone.local)
Constructs a DateTime from an epoch timestamp expressed in seconds.
public DateTime
DateTime(text as String, timeZone as TimeZone = TimeZone.local)
Constructs a DateTime by parsing a complete ISO 8601 date-time string.
public DateTime
DateTime(timestamp as Timestamp, timeZone as TimeZone = TimeZone.local)
Constructs a DateTime from a timestamp.
public DateTime
DateTime(year as Int = 1970, month as Int = 1, day as Int = 1, hour as Int = 0, minute as Int = 0, second as Int = 0, usecond as Int = 0, timeZone as TimeZone = TimeZone.local)
Constructs a DateTime from individual date/time components.
Methods
Modifier and Type Member Description
public override toString
toString() as String
Returns a string representation of this DateTime object using the default locale.
public toString
toString(format as String) as String
Returns a string representation using a custom format and the default locale.
public toString
toString(format as String, locale as Locale) as String
Returns a string representation of this DateTime object using a specific locale.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml
Operators
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.