DateProvides date functions More... Methods
Detailed DescriptionThe QML Date object extends the JS Date object with locale aware functions. Functions that accept a locale format may be either an enumeration value:
or a string specifying the format These expressions may be used for format dates:
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output. Example format strings (assuming that the Date is the 20 July 1969):
These expressions may be used for formatting time:
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output. Example format strings (assuming that the QTime is 14:13:09.042)
If the date is invalid, an empty string will be returned. Note: Using the locale-aware functions to perform date or time formatting can result in incorrectly formatted times, due to an inconsistency in specification between Qt and JS. ECMA-262 specifies that historical dates should be intrepreted by projecting the current rules for daylight-saving onto past years, while Qt uses historical data (where available) to determine whether daylight-saving was in effect for a given date. Therefore, constructing a Date value in JS and converting it to a string using the locale-aware functions can yield a result incorrect by one hour, if DST is currently in effect, while it was not for the time specified, or vice versa. See also Locale. Method DocumentationConverts the Date to a string containing the date suitable for the specified locale in the specified format. If the format is not specified Locale.LongFormat will be used. If locale is not specified, the default locale will be used. The following example shows the current date formatted for the German locale: import QtQuick 2.0 Text { text: "The date is: " + Date().toLocaleDateString(Qt.locale("de_DE")) } Converts the Date to a string containing the date and time suitable for the specified locale in the specified format. If the format is not specified Locale.LongFormat will be used. If locale is not specified, the default locale will be used. The following example shows the current date and time formatted for the German locale: import QtQuick 2.0 Text { text: "The date is: " + Date().toLocaleString(Qt.locale("de_DE")) } Converts the Date to a string containing the time suitable for the specified locale in the specified format. If the format is not specified Locale.LongFormat will be used. If locale is not specified, the default locale will be used. The following example shows the current time formatted for the German locale: import QtQuick 2.0 Text { text: "The date is: " + Date().toLocaleTimeString(Qt.locale("de_DE")) } |