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] Unable to convert string to int to perform MSecsSinceEpoch
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Unable to convert string to int to perform MSecsSinceEpoch

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k 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.
  • H Offline
    H Offline
    holygirl
    wrote on last edited by
    #1

    Hello people!

          I'm trying to convert a string into a date time format in the following way
    

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

    This works well and gives me the correct output as Tuesday, 23 October, 2012 12:56:00 PM
    However, when I store 1350977160000 into a QString and then try to convert it to int , it doesn't seem to give the correct output. Instead, I get Tuesday, 05 February, 2013 5:30:00 AM

    @
    QDateTime timestamp;
    QString s = "1350977160000";

    bool ok;
    
    quint64 dateTime = s.toLong(&ok,10);
    timestamp.setMSecsSinceEpoch(dateTime);
    
    qDebug()<< timestamp.toString(Qt::SystemLocaleLongDate);
    

    @

    Please help me. Where am I going wrong?
    Thanks.

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

      Try this,

      @quint64 dateTime = Q_UINT64_C(1350977160000);@

      or

      Change this
      @quint64 dateTime = s.toLong(&ok,10);@

      to

      @double dateTime = s.toDouble();@

      Hope it should work... :)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        holygirl
        wrote on last edited by
        #3

        @
        double dateTime = s.toDouble();
        @

        This worked! I swear to God I tried this before but it didn't work. But it is now. Grrrr! Such a silly thing. Thank you very much Rochi :)

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

          Your Welcome.. :)

          [quote author="holygirl" date="1360042606"]@
          I swear to God I tried this before but it didn't work. But it is now. [/quote]

          True... Sometimes it happens.... :)

          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