Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Date

Provides date functions More...

Methods

Detailed Description

The QML Date object extends the JS Date object with locale aware functions.

Functions that accept a locale format may be either an enumeration value:

Locale.LongFormatThe long version of the string; for example, returning "January" as a month name.
Locale.ShortFormatThe short version of the string; for example, returning "Jan" as a month name.
Locale.NarrowFormatA special version for use when space is limited; for example, returning "J" as a month name. Note that the narrow format might contain the same text for different months and days or it can even be an empty string if the locale doesn't support narrow names, so you should avoid using it for date formatting. Also, for the system locale this format is the same as ShortFormat.

or a string specifying the format These expressions may be used for format dates:

ExpressionOutput
dthe day as number without a leading zero (1 to 31)
ddthe day as number with a leading zero (01 to 31)
dddthe abbreviated localized day name (e.g. 'Mon' to 'Sun').
ddddthe long localized day name (e.g. 'Monday' to 'Sunday').
Mthe month as number without a leading zero (1 to 12)
MMthe month as number with a leading zero (01 to 12)
MMMthe abbreviated localized month name (e.g. 'Jan' to 'Dec').
MMMMthe long localized month name (e.g. 'January' to 'December').
yythe year as two digit number (00 to 99)
yyyythe year as four digit number. If the year is negative, a minus sign is prepended in addition.

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):

FormatResult
dd.MM.yyyy20.07.1969
ddd MMMM d yySun July 20 69
'The day is' ddddThe day is Sunday

These expressions may be used for formatting time:

ExpressionOutput
hthe hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hhthe hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
Hthe hour without a leading zero (0 to 23, even with AM/PM display)
HHthe hour with a leading zero (00 to 23, even with AM/PM display)
mthe minute without a leading zero (0 to 59)
mmthe minute with a leading zero (00 to 59)
sthe second without a leading zero (0 to 59)
ssthe second with a leading zero (00 to 59)
zthe milliseconds without leading zeroes (0 to 999)
zzzthe milliseconds with leading zeroes (000 to 999)
AP or Ause AM/PM display. AP will be replaced by either "AM" or "PM".
ap or ause am/pm display. ap will be replaced by either "am" or "pm".
tthe timezone (for example "CEST")

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)

FormatResult
hh:mm:ss.zzz14:13:09.042
h:m:s ap2:13:9 pm
H:m:s a14:13:9 pm

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 Documentation

string Date::toLocaleDateString(locale, format)

Converts 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"))
 }

string Date::toLocaleString(locale, format)

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"))
 }

string Date::toLocaleTimeString(locale, format)

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"))
 }

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web