QML type: Locale, Date

Locale

1. Description

This type provides locale-specific properties and formatting data.

Locale objects can only be created with the Qt.locale() function. cannot be created directly.

The Qt.locale() function returns a JS Locale object representing the locale with the specified name in the form “language[_territory][.codeset][@modifier]” or “C”.

Supports the concept of a default locale, which is determined by the system’s locale when the application starts. If no arguments are passed to Qt.locale(), the default locale object is returned.

2. Attribute members

1. amText: string

The localized name with the “AM” suffix for the time using the 12-hour clock.

2. decimalPoint: string

The decimal point character.

3. Exponential: string

Exponent character.

4. firstDayOfWeek: enumeration

The first day of the week.

  • Locale. Sunday = 0
  • Locale. Monday = 1
  • Locale. Tuesday = 2
  • Locale. Wednesday = 3
  • Locale. Thursday = 4
  • Locale. Friday = 5
  • Locale. Saturday = 6

5. groupSeparator: string

Group separator.

6. measurementSystem: enumeration

The unit of measurement.

  • Locale.MetricSystem: Metric units, such as meters, centimeters, and millimeters.
  • Locale.ImperialUSSystem: Imperial units, such as inches and miles used in the United States.
  • Locale.ImperialUKSystem: Imperial units, such as inches and miles used in Great Britain.
  • Locale.ImperialSystem: Provides compatibility. Same as Locale.ImperialUSSystem.

7. name: string

Saves the language and country for this locale as a string of the form “language_country”, where language is a lowercase two-letter ISO 639 language code and country is an uppercase two- or three-letter ISO 3166 country code.

8. nativeCountryName: string

The local name of the country.

9. nativeLanguageName: string

The local name of the language.

10. negativeSign: string

Negative sign character.

11. numberOptions: enumeration

Contains a set of options for number-to-string and string-to-number conversions.

12, percent: string

The percent character.

13. pmText: string

The localized name with the “PM” suffix for the 12-hour time.

14. positiveSign: string

Plus sign character.

15. textDirection: enumeration

The text direction of the language.

Qt.LeftToRight

Qt.RightToLeft

16. uiLanguages: Array

Returns an ordered list of locale names for translation purposes, in order of preference.

The return value represents the locale name in which the user would like to see UI translations.

17, weekDays: Array

The array of days considered weekdays according to the current locale, where Sunday is 0 and Saturday is 6.

18. zeroDigit: string

Zero character.

The benefits of this article,Fees to receive Qt development learning materials package, technical video, including (C++ language foundation, introduction to Qt programming, QT signal and slot mechanism, QT interface development – Image drawing, QT network, QT database programming, QT project actual combat, QT embedded development, Quick module, etc.) ↓↓↓↓↓↓See below↓↓Click at the bottom of the article to receive the fee↓↓

3. Member functions

1. string currencySymbol(format)

Returns the currency symbol in the specified format:

  • Locale.CurrencyIsoCode: The ISO-4217 code of the currency.
  • Locale.CurrencySymbol: Currency symbol.
  • Locale.CurrencyDisplayName: Currency name.

2. string dateFormat(type)

string dateTimeFormat(type)

Returns the date, datetime format used for the current locale. type specifies the FormatType to return. See Date below.

3. string dayName(day, type)

Returns the localized name of the day in an optional FormatType specified by type (day parameter 0 for Sunday, 1 for Monday, etc.).

4. string formattedDataSize(int bytes, int precision, DataSizeFormat format)

Convert byte size to readable localized string. See QLocale::formattedDataSize().

5. string monthName(month, type)

Returns the localized name of the month (0-11) in an optional FormatType specified by type.

6. string standaloneDayName(day, type)

Returns the localized name of the day as standalone text (where 0 represents Sunday, 1 represents Monday, and so on), in the FormatType specified by type.

If the locale information does not specify a separate day name, the return value is the same as in dayName().

7. string standaloneMonthName(month, type)

Returns the localized name (0-11) of the month as standalone text, in the optional FormatType specified by type.

If the locale information does not specify a separate month name, the return value is the same as in monthName().

8. string timeFormat(type)

Returns the time format used for the current locale. type specifies the FormatType to return.

Date

1. Description

The Date object extends the JS Date object with locale setting functionality.

2. Format enumeration value

Use enumeration values when a format matching a locale preference is required:

  • Locale.LongFormat: longer format
  • Locale.ShortFormat: Shorter format
  • Locale.NarrowFormat : Same as Locale.ShortFormat in context

The format of the enum representation will depend on the locale, but also on the method using the enum.

For example, for the en_US locale, use the following format string:

3. Member functions

1. string fromLocaleDateString(locale, dateString, format)

Converts a date string dateString to a Date object using the locale and format.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQml 2.0

QtObject {
property var locale: Qt.locale()
property date currentDate: new Date()
property string dateString

Component.onCompleted: {
dateString = currentDate.toLocaleDateString();
print(Date. fromLocaleDateString(dateString));
}
}

2. string fromLocaleString(locale, dateTimeString, format)

Converts a datetime string dateTimeString to a Date object using the locale and format.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQml 2.0

QtObject {
property var locale: Qt.locale()
property string dateTimeString: "Tue 2013-09-17 10:56:06"

Component.onCompleted: {
print(Date. fromLocaleString(locale, dateTimeString, "ddd yyyy-MM-dd hh:mm:ss"));
}
}

3. string fromLocaleTimeString(locale, timeString, format)

Converts the time string timeString to a Date object using the locale and format.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQml 2.2

QtObject {
property var locale: Qt.locale()
property date currentTime: new Date()
property string timeString

Component.onCompleted: {
timeString = currentTime.toLocaleTimeString(locale, Locale.ShortFormat);
print(Date. fromLocaleTimeString(locale, timeString, Locale. ShortFormat));
}
}

4. string timeZoneUpdated()

Notifies the JS engine that the system’s time zone has changed, which is required for correct manipulation of datetime data.

This function should be called after the system time zone has been updated.

Applications that change the time zone will call timeZoneUpdated() after setting the new time zone:

property string selectedTimeZone

onSelectedTimeZoneChanged: {
MyFunctions.setSystemTimeZone(selectedTimeZone)
Date. timeZoneUpdated()
}

5. string toLocaleDateString(locale, format)

Converts a Date to a string containing a date in the specified format for the specified locale.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQuick 2.0

Text {
text: "The date is: " + new Date().toLocaleDateString(Qt.locale("de_DE"))
}

6. string toLocaleString(locale, format)

Converts a Date to a string containing the date and time for the specified locale in the specified format.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQuick 2.0

Text {
text: "The date is: " + new Date().toLocaleString(Qt.locale("de_DE"))
}

7. string toLocaleTimeString(locale, format)

Converts a Date to a string containing the time for the specified locale in the specified format.

If no format is specified, Locale.LongFormat will be used.

If no locale is specified, the default locale will be used.

import QtQuick 2.0

Text {
text: "The date is: " + new Date().toLocaleTimeString(Qt.locale("de_DE"))
}

The benefits of this article,Fees to receive Qt development learning materials package, technical video, including (C++ language foundation, introduction to Qt programming, QT signal and slot mechanism, QT interface development – Image drawing, QT network, QT database programming, QT project actual combat, QT embedded development, Quick module, etc.) ↓↓↓↓↓↓See below↓↓Click at the bottom of the article to receive the fee↓↓