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. [SOLVED] Help with converting old date to current date
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Help with converting old date to current date

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hey everybody!

            I have a set of numbers which represent the date and time in milliseconds. I'm converting them to human understandable form by using
    

    @
    int time_in_msecs = 1350891180000;
    QDateTime timestamp;
    timestamp.setMSecsSinceEpoch(1350891180000);
    qDebug() << timestamp.toString(Qt::SystemLocaleLongDate);
    @

    I get the output as Monday, 22 October, 2012 1:03:00 PM . What I want to do is, each time I run my application, I want the date to be the current date. Time can remain the same.
    So even if it is Monday, 22 October, 2012 1:03:00 PM , I want it to be converted to Tuesday, 29 January, 2013 1:03:00 PM
    Any ideas on how I can do this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Macro
      wrote on last edited by
      #2

      Hi....

      Try this....

      @qDebug() << timestamp.toString(QDateTime::currentDateTime().toString());@

      Note: if you want to change only the date, then use

      @QDate::currentDate()@

      Thanks & Regards

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi Rochi!

          I already tried what you suggested. Using _QDate_ or _QDateTime_ gives me the current date and the current time. What I want is to retain the _time_ which is there in _time-in-msecs_ while only changing its _date_ part.
        

        Thanks.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Macro
          wrote on last edited by
          #4

          Hi holygirl,

          then please try this.

          @timestamp.setMSecsSinceEpoch(1350891180000);
          timestamp.setDate(QDate::currentDate());
          qDebug() << timestamp.toString(Qt::SystemLocaleLongDate);@

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yep. That worked so well. Thank you so much Rochi :)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Macro
              wrote on last edited by
              #6

              welcome... :-)

              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