Results 1 to 3 of 3

Thread: QLocale and date

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QLocale and date

    Hi, have a problem with localized date representation. Dates are in the following format:

    2012-05-01

    My system is using the it_IT locale as QLocale::system().name() confirms. But

    Qt Code:
    1. date.toString(Qt::SystemLocaleShortDate)
    To copy to clipboard, switch view to plain text mode 

    returns the english string "1 May 2012" instead of the italian "1 Mag 2012"

    Seems that the only option to have an italian localization is to use:

    Qt Code:
    1. QLocale locale;
    2. QLocale::setDefault(locale.name());
    3. locale.toString(date, QLocale::ShortFormat)
    To copy to clipboard, switch view to plain text mode 

    But the returned string is "01/05/2012", while if using QLocale::LongFormat I got "martedì 1 maggio 2012" that is correct, but too long.

    With locale.toString(date, "dd MMMM yyyy") I obtain the desired format but since I will release the code I would prefer a more clean solution.

    Thanks.
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLocale and date

    I'm having a similar problem too.

    We need to localise a date to display someone's date of birth so are using QLocale::dateFormat. However, this only returns the short format ('11/06/2006') or the long format ('Domingo, 11 de Junho de 2006') and we want an equivalent to the long format without the day name.

    If we strip out 'dddd' from the date format we end up with ', 11 de Junho de 2006' which is wrong as there is a comma and no guarantee it is grammatically correct in the given language. For example, some languages may say 'the saturday' instead of 'saturday' so stripping out the day name will leave in an extra 'the'.

    Obviously, I can pass in my own date format as jiveaxe does above but then that isn't localised properly.

  3. #3
    Join Date
    Apr 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLocale and date

    Hi! You can parse string returned from QLocale::dateFormat() to remove unnecessary date parts...

    QString::split(" ")

Similar Threads

  1. QLocale not retreiving language right
    By jfjf in forum Newbie
    Replies: 2
    Last Post: 5th February 2011, 08:42
  2. Set QLocale local once or in every class?
    By homerun4711 in forum Newbie
    Replies: 1
    Last Post: 19th January 2011, 10:54
  3. QLocale/Resource
    By coderbob in forum Newbie
    Replies: 4
    Last Post: 21st November 2007, 20:51
  4. QLocale confusion :(
    By gri in forum Qt Programming
    Replies: 6
    Last Post: 15th June 2007, 13:09
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.