Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Force QDateTime.toString() to display UTC time
Qt 6.11 is out! See what's new in the release blog

Force QDateTime.toString() to display UTC time

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 951 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Queequeg
    wrote on last edited by
    #1

    How do I force QDateTime.toString () to display UTC time?
    If I change the time zone on my computer, then the output of the function also changes. It's pretty obvious, so I added setTimeSpec(Qt::UTC) but it still doesn't work!
    I think I am using this incorrectly?
    How can I force toString to output timestamp exclusively in UTC format without being bound to the local machine time zone?

    This code:
    e0f0e2e7-4c86-4029-93d9-e9b1920e6668-image.png
    Output:
    1b8dcec9-b458-4083-b54f-c2e2ec5e174a-image.png

    This code:
    b776796b-7900-44f2-b41c-945a251dd5b0-image.png
    Output:
    10f4acbd-7fa4-48c8-8663-45bc4cb3e449-image.png

    1 Reply Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      As stated in the documentation you need to use QDateTime::toUTC().

      For more information please re-read.

      Kind Regards,
      Artur

      Q 1 Reply Last reply
      4
      • artwawA artwaw

        As stated in the documentation you need to use QDateTime::toUTC().

        Q Offline
        Q Offline
        Queequeg
        wrote on last edited by
        #3

        @artwaw Yes, really, thanks, missed it!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved