×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    27

    Qt.formatTime not formatted according to locale?

    I have a javascript Date object that I format with Qt.formatTime in my QML application like this:

    Qt.formatTime(dateObject)

    From the Qt documentation I was expecting this to be formatted according to the system locale, but instead it always appears on N9 as e.g. "09:58" (whereas I was expecting "9:58" or "09:58 AM" depending on the regional settings).

    Does anybody know what is wrong?

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: Qt.formatTime not formatted according to locale?

    Hi,

    the doc says if format is not specified, time is formatted using Qt.DefaultLocaleShortDate.

    Qt::SystemLocaleShortDate is for OS setting of date. Did you try giving this as the second arg in Qt.formatTime

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    27

    Re: Qt.formatTime not formatted according to locale?

    Quote Originally Posted by kusumk View Post
    Hi,

    the doc says if format is not specified, time is formatted using Qt.DefaultLocaleShortDate.

    Qt::SystemLocaleShortDate is for OS setting of date. Did you try giving this as the second arg in Qt.formatTime
    I did, but the result was the same.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: Qt.formatTime not formatted according to locale?

    Hi,

    Seems the binding is not done,
    I have tried with the options too and it always shows the same time and never as per locale atleast.

    https://bugreports.qt-project.org/browse/QTBUG-15416
    This bug seems to be reported for the same issue.

  5. #5
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Qt.formatTime not formatted according to locale?

    Hi,
    I tried the following code and actually it doesn't work for me too.

    import QtQuick 1.1

    Rectangle {
    width: 360
    height: 360
    //property time mTime: "20:10:00"

    Text {
    id: mText
    //text: Qt.formatTime(mTime);
    anchors.centerIn: parent
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    Qt.quit();
    }
    }

    Component.onCompleted: {
    var dateTime = new Date(2001, 5, 21, 14, 13, 09)
    mText.text = Qt.formatTime(dateTime, Qt.SystemLocaleShortDate);
    }
    }

    Here are the issues I found:
    1. time property is missing in QML. Please correct me if I'm wrong.
    2. locale doesn't work since system locale is not properly detected. (qDebug() << "LOCALE" << QLocale::system().name()

  6. #6
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,957

    Re: Qt.formatTime not formatted according to locale?

    May be you can customize as how would you like to see the format, like i tried this:

    Qt.formatTime(new Date(2001, 5, 21, 9, 58, 09), "h:m ap") & what is get it 9:58 am.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: Qt.formatTime not formatted according to locale?

    Yes, that can be done always, but it would be a sort of hardcoding, and if the system locale is changed then it still wouldnt match.

  8. #8
    Registered User
    Join Date
    Oct 2009
    Posts
    39

    Re: Qt.formatTime not formatted according to locale?

    Quote Originally Posted by kusumk View Post
    Yes, that can be done always, but it would be a sort of hardcoding, and if the system locale is changed then it still wouldnt match.
    I had this problem with Bedside, and the behaviour differs between Symbian, Maemo & Harmattan.

    I've tried to handle it by exposing a property from C++, which goes to MTF to read the Harmattan settings.

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    27

    Re: Qt.formatTime not formatted according to locale?

    Yeah, it seems that MLocale is the way to go (QLocale also doesn't work). This is what I used:

    MLocale* mLocale = new MLocale();
    mLocale->formatDateTime(dateTime, MLocale:ateNone, MLocale::TimeShort);

    There is also a signal to listen for changes in locale settings.

Similar Threads

  1. Somebody Cloned my phone, Can be formatted?
    By Augustino in forum General Development Questions
    Replies: 2
    Last Post: 2010-11-30, 05:03
  2. ip address formatted textbox
    By mt.jijo in forum Symbian
    Replies: 5
    Last Post: 2009-06-19, 14:38
  3. 9500 with fw 5.22 can't be formatted?
    By centaurea in forum General Development Questions
    Replies: 0
    Last Post: 2005-09-21, 13:34
  4. Formatted Printing To a File
    By LAS__VEGAS in forum Symbian
    Replies: 0
    Last Post: 2005-03-03, 13:02
  5. how to send 8 bit formatted data
    By aliakkaya in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2002-09-18, 07:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •