DateTime

Description

The DateTime object represents a date including a time to specify a certain absolute point in time. It provides mechanisms for easily formatting a date and/or time into a string, handling timezones and querying precise milliseconds-based timestamps from the system.

› Inherits:DataObject

Properties

currentMSecsSinceEpoch

This property holds the number of milliseconds since 1970-01-01T00:00:00 Universal Coordinated Time. This number is like the POSIX time_t variable, but expressed in milliseconds instead.

Note

For performance reason this property is not updated automatically and has to be read explicitely whenever required. This property therefore can’t be used in bindings expressions and is only evaluated once.

› Type:SignedBigInteger
› Attributes:Readonly

currentSecsSinceEpoch

This property holds the number of seconds since 1970-01-01T00:00:00 Universal Coordinated Time.

› Type:SignedBigInteger
› Signal:currentSecsSinceEpochChanged()
› Attributes:Readonly

dateFormat

This property holds the used dateFormat to format string, if formatString is left blank.

› Type:DateFormat
› Default:DateTime.FormatText
› Signal:dateFormatChanged()
› Attributes:Writable

formatString

This property holds the format string which is used to format string if set.

Table 11 Format codes
d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. ‘Mon’ to ‘Sun’). Uses the system locale to localize the name
dddd the long localized day name (e.g. ‘Monday’ to ‘Sunday’). Uses the system locale to localize the name
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. ‘Jan’ to ‘Dec’). Uses the system locale to localize the name
MMMM the long localized month name (e.g. ‘January’ to ‘December’). Uses the system locale to localize the name
yy the year as two digit number (00-99)
yyyy the year as four digit number
h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H the hour without a leading zero (0 to 23, even with AM/PM display)
HH the hour with a leading zero (00 to 23, even with AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the whole second without a leading zero (0 to 59)
ss the whole second with a leading zero where applicable (00 to 59)
z the fractional part of the second, to go after a decimal point, without trailing zeroes (0 to 999)
zz the fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999)
AP or A use AM/PM display. A/AP will be replaced by either “AM” or “PM”
ap or a use am/pm display. a/ap will be replaced by either “am” or “pm”
t the timezone abbreviation (for example “CEST”)
› Type:String
› Signal:formatStringChanged()
› Attributes:Writable

highPrecisionString

This property holds a formatted string including milliseconds. If a custom formatString is used it has to be ensured that it includes placeholders for milliseconds as these will be omitted otherwise.

Note

For performance reason this property is not updated automatically and has to be read explicitely whenever required. This property therefore can’t be used in bindings expressions and is only evaluated once.

› Type:String
› Attributes:Readonly

running

This property holds whether the currentSecsSinceEpoch property and corresponding properties such as string are updated automatically every second.

This property was introduced in InCore 2.5.

› Type:Boolean
› Default:true
› Signal:runningChanged()
› Attributes:Writable

string

This property holds a formatted and constantly updated string representing the current time. If formatString is set it is used for formatting, otherwise dateFormat is used.

› Type:String
› Signal:stringChanged()
› Attributes:Readonly

timeZone

This property holds the timezone which should used. Check availableTimeZones() for a list of all available time zone ids.

› Type:String
› Signal:timeZoneChanged()
› Attributes:Writable

Methods

availableTimeZones()

This method returns a list of all available time zones.

› Returns:StringList

parseToString(Variant data, DateTime.DateFormat dateFormat, String timeZone)

› Returns:String

Enumerations

DateFormat

This enumeration describes all supported predefined date formats.

Name Value Description
DateTime.FormatText 0 The default format, which includes the day and month name, the day number in the month, and the year in full. The day and month names will be short, localized names. This is basically equivalent to using the date format string, “ddd MMM d yyyy”.
DateTime.FormatISO 1 ISO 8601 extended format: yyyy-MM-ddTHH:mm:ss (e.g. 2019-04-02T10:30:29) or with a time-zone suffix (Z for UTC otherwise an offset as [+|-]HH:mm) if set.
DateTime.FormatLocalizedShort 6 The short version of day and month names, for example “Jan” as a month name.
DateTime.FormatLocalizedLong 7 The short version of day and month names, for example “January” as a month name.
DateTime.FormatRFC2822 8 RFC 2822, RFC 850 and RFC 1036 format: either [ddd,] dd MMM yyyy hh:mm[:ss] +/-TZ or ddd MMM dd yyyy hh:mm[:ss] +/-TZ.
DateTime.FormatISOWithMs 9 ISO 8601 extended format (DateTime.FormatISO) including milliseconds.

Example

import InCore.Foundation 2.5

Application {


    DateTime {
        id: dateTime0
        dateFormat: DateTime.FormatISO

        onStringChanged: console.log( "current date time is (human reable and unix)", string, currentSecsSinceEpoch )
    }

    DateTime {
        id: dateTime1
        formatString: "MMdd"

        onStringChanged: if( string === "0504" ) console.log( "May the fourth be with you!" )
    }

    DateTime {
        id: dateTime2
        dateFormat: DateTime.FormatISOWithMs
        // onHighPrecisionStringChanged will not work
    }

    Timer {
        interval: 500
        onTriggered: console.log( "high precision date time", dateTime2.highPrecisionString )
    }
}