Results 1 to 5 of 5

Thread: Qt 5.7 QTimeZone::abbreviation()

  1. #1
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Qt 5.7 QTimeZone::abbreviation()

    I would like to display the local time zone as an abbreviation similar to CST, CDT, etc. The QTimeZone class returns "Central Daylight Time" for the abbreviation function. This does not seem to be abbreviated at all. I would have expected the common "CDT" abbreviation instead.

    Here is the code:
    Qt Code:
    1. QDateTime curtim = QDateTime::currentDateTime();
    2. ui->lblCurTime->setText(curtim.toString("hh:mm:ss"));
    3. mwd->TZ = curtim.timeZone();
    4. QString abbr = mwd->TZ = curtim.timeZone().abbreviation();
    5. ui->lblTZ->setText(abbr);
    To copy to clipboard, switch view to plain text mode 

    The output looks like 12:30:30 Central Daylight Time

    Environment:
    OS: Windows 10 32-bit
    Qt: v5.7.1 MinGW 5.3.0 32-bit

    Note: Same problem exists on Linux Mint 17.3 32-bit

    What am I doing wrong?

  2. #2
    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: Qt 5.7 QTimeZone::abbreviation()

    How does that even comile?

    QTimeZone::abbreviation() has a required argument?

    Anyway, have you tried QTimeZone::displayName() with QTimeZone::ShortName?

    Cheers,
    _

  3. #3
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 5.7 QTimeZone::abbreviation()

    Well maybe it is a bug. Not sure. I will modify my code and try your suggestion.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Qt 5.7 QTimeZone::abbreviation()

    Quote Originally Posted by ad5xj View Post
    What am I doing wrong?
    This works for me:

    Qt Code:
    1. QDateTime curtim = QDateTime::currentDateTime();
    2. QString abbr = curtim.timeZoneAbbreviation();
    3. qDebug() << "Current time: " << curtim.toString("hh:mm:ss t");
    4. qDebug() << "TZ=" << abbr;
    To copy to clipboard, switch view to plain text mode 

    Output:

    Qt Code:
    1. Current time: "15:00:01 CDT"
    2. TZ= "CDT"
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 5.7 QTimeZone::abbreviation()

    Thanks jefftee that works great!

Similar Threads

  1. QTimeZone
    By QPlace in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2011, 15:03

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.