Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3312396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:59:25+00:00 2026-05-17T21:59:25+00:00

I construct a QDateTime from a string like this: QDateTime date = QDateTime::fromString(2010-10-25T10:28:58.570Z, yyyy-MM-ddTHH:mm:ss.zzzZ);

  • 0

I construct a QDateTime from a string like this:

QDateTime date = QDateTime::fromString("2010-10-25T10:28:58.570Z", "yyyy-MM-ddTHH:mm:ss.zzzZ");

I know that date is in UTC because that is the way it’s stored. But when I want to display this date to the user, it should be in the user’s local time zone. date.toLocalTime() looks promising, but it returns the exact same date!

How do I convert date to the system’s local time to display to the user?

Here are some more failures:

#include <QtCore/QCoreApplication>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QDateTime date = QDateTime::fromString("2010-10-25T10:28:58.570Z", "yyyy-MM-ddTHH:mm:ss.zzzZ");
    QDateTime local = date.toLocalTime();

    qDebug() << "utc: " << date;
    qDebug() << "local: " << local.toString();
    qDebug() << "hax: " << local.toString(Qt::SystemLocaleLongDate);

    return a.exec();
}

Output:

utc:  QDateTime("Mon Oct 25 10:28:58 2010")
local:  "Mon Oct 25 10:28:58 2010"
hax:  "Monday, October 25, 2010 10:28:58 AM"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:59:26+00:00Added an answer on May 17, 2026 at 9:59 pm

    QDateTime knows whether it is UTC or local time. For example:

    QDateTime utc = QDateTime::currentDateTimeUtc();
    QDateTime local = QDateTime::currentDateTime();
    
    local.secsTo(utc) // zero; these dates are the same even though I am in GMT-7
    

    We need to tell date that it is a UTC date time with date.setTimeSpec(Qt::UTC):

    #include <QtCore/QCoreApplication>
    #include <QtCore/QDateTime>
    #include <QtCore/QDebug>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QDateTime date = QDateTime::fromString("2010-10-25T10:28:58.570Z", "yyyy-MM-ddTHH:mm:ss.zzzZ");
        date.setTimeSpec(Qt::UTC);
        QDateTime local = date.toLocalTime();
    
        qDebug() << "utc: " << date;
        qDebug() << "local: " << local.toString();
        qDebug() << "hax: " << local.toString(Qt::SystemLocaleLongDate);
    
        return a.exec();
    }
    

    Output:

    utc:  QDateTime("Mon Oct 25 10:28:58 2010") 
    local:  "Mon Oct 25 03:28:58 2010" 
    hax:  "Monday, October 25, 2010 3:28:58 AM"
    

    I’m in GMT-7, so this is right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I construct my ajaxSend call, this seems like the place to put
If I want to construct a std::string with a line like: std::string my_string(a\0b); Where
I need to construct a DateTime object with the date coming from a calendar
How can I construct the following string in an Excel formula: Maurice "The Rocket"
I'm getting this error on my production environnent: (from prod.log) [2012-01-30 17:00:51] request.CRITICAL: Doctrine\ORM\Mapping\MappingException:
I need to construct a DateTime from an integer Unix timestamp 1329272833 . The
I need to construct linq, but day (date time type, i.AllowedTime.AllowedDate.Day), hours and minutes
I'm parsing a feed that contains a created at entry, formatted like this: Thu,
In this situation I am trying to perform a data import from an XML
so, I've got something like this: there's an ASP.NET application (1) that references WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.