[SOLVED] Help with converting old date to current date

  • 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;
    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?

  • Hi....

    Try this....

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

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


    Thanks & Regards

  • 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.


  • Hi holygirl,

    then please try this.

    qDebug() << timestamp.toString(Qt::SystemLocaleLongDate);@

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

  • welcome... :-)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.