Results 1 to 4 of 4

Thread: QDate SystemLocaleShortDate without year

  1. #1
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default QDate SystemLocaleShortDate without year

    I'm using QDate.toString() to show a date for the user. Right now I'm using Qt::SystemLocaleShortDate to get a short date format with localization. It works perfect but I need the format without the year. Now it shows for example: "20.07.1969" I want only "20.07". Is this possible but still get it localized?

  2. #2
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QDate SystemLocaleShortDate without year

    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  3. #3
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default Re: QDate SystemLocaleShortDate without year

    Thanks! But will that take care of localization? For example if I use toString("dd.MM"), will that show dd/MM if in europe and MM/dd if in US?

  4. #4
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QDate SystemLocaleShortDate without year

    I did not look the API very closely so next proposal might be a bit dumb but anyway it might be one way of doing what you want.

    1)
    - Use QLocale::system().dateFormat(QLocale::ShortFormat) to read the date format of the current locale
    - Use QRegExp to remove year part and separator from the locale string (for example from "M/d/yy" --> "M/d")
    - Use toString to format the date without year number

    2)
    - Use QRegExp to remove year number and the separator that might be before or after the year in the string

    Both of those will give you a localized date as you wanted, the "difficult" part is to figure out the correct regular expression to remove either the year number or yy from the string and the ./ or whatever separator character that might be before or after the year.

    But as said, not the prettiest way of solving this issue, I indeed hope that there is some API method for this

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

    martinn (24th February 2010)

Similar Threads

  1. Happy New Year!!!
    By fengtian.we in forum General Discussion
    Replies: 6
    Last Post: 4th January 2012, 06:07
  2. Merry Christmas and a Happy New Year 2008
    By vermarajeev in forum General Discussion
    Replies: 1
    Last Post: 24th December 2007, 20:40
  3. Replies: 1
    Last Post: 24th December 2007, 11:29
  4. hello. happy new year
    By Andrewliu in forum General Discussion
    Replies: 4
    Last Post: 30th December 2006, 19:35

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.