Results 1 to 4 of 4

Thread: Get English date format from in foreign locale

  1. #1
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Get English date format from in foreign locale

    I have a date string in English format as follow "05 May 2013", I used QDate::fromString to create a Date object from this string, but if I run my program in another PC which system locale is Germany the QDate::fromString can not parse the string because QDate::fromString will be localized according to the system's default locale settings.

    So how can I set the English locale as default to get the correct date string in any PC with any system's default locale settings?

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get English date format from in foreign locale

    try:

    QLocale locale () const
    void setLocale ( const QLocale & locale )
    void unsetLocale ()

    and after reset default locale...

  3. The following user says thank you to patrik08 for this useful post:

    nhocjerry (2nd October 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get English date format from in foreign locale

    You have two options:

    - You can change the locale for your program, see QLocale::setDefault().
    - You can create a QLocale object for an English locale and use it to parse the date string, see QLocale::toDate()

    I would suggest you do the latter.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    nhocjerry (2nd October 2013)

  6. #4
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Re: Get English date format from in foreign locale

    Thanks all, it works perfectly

Similar Threads

  1. How to get the custom date and time format???
    By Gokulnathvc in forum Newbie
    Replies: 7
    Last Post: 29th July 2011, 22:47
  2. Replies: 1
    Last Post: 24th April 2010, 15:31
  3. Date format is not display
    By sosanjay in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 10:26
  4. Date and Time format.
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2008, 11:36
  5. Replies: 7
    Last Post: 17th November 2007, 11:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.