简体   繁体   中英

Qml Locale has same format for ShortFormat and NarrowFormat

I'm trying to display the date (and time) using the toLocaleDateString / toLocateTimeString methods implemented on the Date type in Qml ( doc here ). It works, except for the ShortFormat which is the same as the NarrowFormat.

Here's an example:

import QtQuick 2.3

import QtQuick.Controls 1.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    property var locale: Qt.locale()

    Label {
        id: date
        text: {
            "DATE: \n" +
              "Locale.LongFormat:\t" + new Date().toLocaleDateString(locale, Locale.LongFormat) + "\n" +
              "Locale.ShortFormat:\t" + new Date().toLocaleDateString(locale, Locale.ShortFormat) + "\n" +
              "Locale.NarrowFormat:\t" + new Date().toLocaleDateString(locale, Locale.NarrowFormat) + "\n"
        }
        anchors.top : parent
    }

    Label {
        id: time
        text:
            "TIME: \n" +
              "Locale.LongFormat:\t" + new Date().toLocaleTimeString(locale, Locale.LongFormat) + "\n" +
              "Locale.ShortFormat:\t" + new Date().toLocaleTimeString(locale, Locale.ShortFormat) + "\n" +
              "Locale.NarrowFormat:\t" + new Date().toLocaleTimeString(locale, Locale.NarrowFormat) + "\n"

        anchors.top: date.bottom
    }

}

What's displayed:

Locale.LongFormat:  Wednesday, September 27, 2017
Locale.ShortFormat: 9/27/17
Locale.NarrowFormat:    9/27/17

Locale.LongFormat:  11:46:10 AM CEST
Locale.ShortFormat: 11:46 AM
Locale.NarrowFormat:    11:46 AM

I was expecting the ShotFormat to give me the date as Sept 27th 2017 or something similar, and the time as 11:46:42 AM.

I found in the doc ( here ), about the NarrowFormat, that

Also, for the system locale this format is the same as ShortFormat.

I'm not sure if this is related to my issue, since I'm explicitly giving the locale in the toLocaleDateMethod. Even then, the NarrowFormat should then be more verbose, instead of the ShortFormat being shorter...

Thanks for your help !

In Qml Documentation:

Locale.ShortFormat is the default and recommended format, as Locale.NarrowFormat may not be fully supported by each locale (see Locale String Format Types) and Locale.LongFormat may not fit within the header cells.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM