1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
30 \inqmlmodule QtQuick 2
31 \brief The Date object provides date functions
33 The QML Date object extends the JS Date object with
34 locale aware functions.
36 Functions that accept a locale format may be either an enumeration
39 \row \i Locale.LongFormat \i The long version of the string; for example, returning "January" as a month name.
40 \row \i Locale.ShortFormat \i The short version of the string; for example, returning "Jan" as a month name.
41 \row \i Locale.NarrowFormat \i A special version for use when space is limited;
42 for example, returning "J" as a month name. Note that the narrow format might contain
43 the same text for different months and days or it can even be an empty string if the
44 locale doesn't support narrow names, so you should avoid using it for date formatting.
45 Also, for the system locale this format is the same as ShortFormat.
48 or a string specifying the format These expressions may be used for format dates:
50 \header \i Expression \i Output
51 \row \i d \i the day as number without a leading zero (1 to 31)
52 \row \i dd \i the day as number with a leading zero (01 to 31)
54 \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
56 \i the long localized day name (e.g. 'Monday' to 'Sunday').
57 \row \i M \i the month as number without a leading zero (1 to 12)
58 \row \i MM \i the month as number with a leading zero (01 to 12)
60 \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
62 \i the long localized month name (e.g. 'January' to 'December').
63 \row \i yy \i the year as two digit number (00 to 99)
64 \row \i yyyy \i the year as four digit number. If the year is negative,
65 a minus sign is prepended in addition.
68 All other input characters will be ignored. Any sequence of characters that
69 are enclosed in singlequotes will be treated as text and not be used as an
70 expression. Two consecutive singlequotes ("''") are replaced by a singlequote
73 Example format strings (assuming that the Date is the 20 July
77 \header \o Format \o Result
78 \row \o dd.MM.yyyy \o 20.07.1969
79 \row \o ddd MMMM d yy \o Sun July 20 69
80 \row \o 'The day is' dddd \o The day is Sunday
83 These expressions may be used for formatting time:
86 \header \i Expression \i Output
88 \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
90 \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
92 \i the hour without a leading zero (0 to 23, even with AM/PM display)
94 \i the hour with a leading zero (00 to 23, even with AM/PM display)
95 \row \i m \i the minute without a leading zero (0 to 59)
96 \row \i mm \i the minute with a leading zero (00 to 59)
97 \row \i s \i the second without a leading zero (0 to 59)
98 \row \i ss \i the second with a leading zero (00 to 59)
99 \row \i z \i the milliseconds without leading zeroes (0 to 999)
100 \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
102 \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
104 \i use am/pm display. \e ap will be replaced by either "am" or "pm".
105 \row \i t \i the timezone (for example "CEST")
108 All other input characters will be ignored. Any sequence of characters that
109 are enclosed in singlequotes will be treated as text and not be used as an
110 expression. Two consecutive singlequotes ("''") are replaced by a singlequote
113 Example format strings (assuming that the QTime is 14:13:09.042)
116 \header \i Format \i Result
117 \row \i hh:mm:ss.zzz \i 14:13:09.042
118 \row \i h:m:s ap \i 2:13:9 pm
119 \row \i H:m:s a \i 14:13:9 pm
122 If the date is invalid, an empty string will be returned.
124 \sa {QtQuick2::Locale}{Locale}
128 \qmlmethod string Date::toLocaleString(locale,format)
130 Converts the Date to a string containing the date and time
131 suitable for the specified \a locale
132 in the specified \a format.
134 If the format is not specified Locale.LongFormat will be used.
136 If \a locale is not specified, the default locale will be used.
138 The following example shows the current date and time formatted
139 for the German locale:
144 text: "The date is: " + Date().toLocaleString(Qt.locale("de_DE"))
150 \qmlmethod string Date::toLocaleDateString(locale,format)
152 Converts the Date to a string containing the date suitable for the specified \a locale
153 in the specified \a format.
155 If the format is not specified Locale.LongFormat will be used.
157 If \a locale is not specified, the default locale will be used.
159 The following example shows the current date formatted
160 for the German locale:
165 text: "The date is: " + Date().toLocaleDateString(Qt.locale("de_DE"))
171 \qmlmethod string Date::toLocaleTimeString(locale,format)
173 Converts the Date to a string containing the time suitable for the specified \a locale
174 in the specified \a format.
176 If the format is not specified Locale.LongFormat will be used.
178 If \a locale is not specified, the default locale will be used.
180 The following example shows the current time formatted
181 for the German locale:
186 text: "The date is: " + Date().toLocaleTimeString(Qt.locale("de_DE"))