DateTime
classin packageklyn.time
public class DateTime extends Object implements ValueType:
└ DateTime
All Implemented Interfaces: ValueType
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.
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
@since 1.0
Properties
Modifier and Type Member Description
public readonly property day
day as Int:
Day component.
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.
public static readonly property now
now as DateTime:
Returns the current date and time.
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:
No summary.
public readonly property usecond
usecond as Int:
Microsecond component.
public readonly property year
year as Int:
Year component.
Properties inherited from Object: type
Constructors
Modifier and Type Member Description
public DateTime
DateTime(timestamp as Timestamp, timeZone as TimeZone = TimeZone.UTC):
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.UTC):
Constructs a DateTime from individual date/time components.
Methods
Modifier and Type Member Description
public static fromTimestamp
fromTimestamp(timestamp as Timestamp, timeZone as TimeZone = TimeZone.UTC) as DateTime:
Constructs a DateTime object from a timestamp.
public override toString
toString(format as String = "%Y-%m-%d %H:%M:%S") as String:
Returns a string representation of this DateTime object.
Methods inherited from Object: fromJson, toDict, toJson, 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.