0

Qml の Date タイプに実装された toLocaleDateString / toLocateTimeString メソッドを使用して、日付 ​​(および時刻) を表示しようとしています (ドキュメントはこちら)。NarrowFormat と同じ ShortFormat を除いて、機能します。

次に例を示します。

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
    }

}

表示される内容:

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

私は、ShotFormat が 2017 年 9 月 27 日または類似の日付と、午前 11:46:42 の時刻を提供することを期待していました。

NarrowFormat についてのドキュメント ( here ) で見つけました。

また、システム ロケールの場合、この形式は ShortFormat と同じです。

toLocaleDateMethod でロケールを明示的に指定しているため、これが私の問題に関連しているかどうかはわかりません。その場合でも、ShortFormat が短くなるのではなく、NarrowFormat をより詳細にする必要があります...

ご協力いただきありがとうございます !

4

1 に答える 1