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. Problem to convert datetime to time_t
Forum Update on Monday, May 27th 2025

Problem to convert datetime to time_t

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.9k Views
  • 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.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on 2 Jan 2017, 18:23 last edited by Stefanoxjx 1 Feb 2017, 18:25
    #1

    Hi, I've a problem and I don't understand if it is a bug.
    I would like to convert QDateTime in time_t, but the result is always 4294967295 equivalent to 07 feb 2006 07:28.
    If I work with date/time lower than 07 feb 2006 07:28 the conversion result is good.
    I think that is a bug.

    I use Qt Creator 4.1.0 Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit) under Debian Jessie.

    The code line that should convert date time in time_t is:

    qDebug() << QDateTime(ui->editDTStart->dateTime()).toTime_t();
    

    What do you think?

    ManyThanks

    Stefano

    A 1 Reply Last reply 2 Jan 2017, 19:54
    0
    • S Stefanoxjx
      2 Jan 2017, 18:23

      Hi, I've a problem and I don't understand if it is a bug.
      I would like to convert QDateTime in time_t, but the result is always 4294967295 equivalent to 07 feb 2006 07:28.
      If I work with date/time lower than 07 feb 2006 07:28 the conversion result is good.
      I think that is a bug.

      I use Qt Creator 4.1.0 Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit) under Debian Jessie.

      The code line that should convert date time in time_t is:

      qDebug() << QDateTime(ui->editDTStart->dateTime()).toTime_t();
      

      What do you think?

      ManyThanks

      Stefano

      A Offline
      A Offline
      ambershark
      wrote on 2 Jan 2017, 19:54 last edited by
      #2

      @Stefanoxjx Worked fine for me... I used this code to test with qt 5.7 on linux:

      #include <QDateTime>
      #include <QDebug>
      
      int main(int ac, char **av)
      {
              QDateTime dt = QDateTime::currentDateTime();
              qDebug() << "date time is: " << dt.toTime_t();
              QDateTime dt2 = QDateTime::fromTime_t(dt.toTime_t());
              qDebug() << "dt2: " << dt2;
              return 0;
      }
      

      Output was as expected with the current local time and the converted time_t was correct with current local as well.

      My guess is you are getting a bad value from your UI control. No bug that I can find in Qt's QDateTime.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      S 1 Reply Last reply 2 Jan 2017, 22:48
      2
      • A ambershark
        2 Jan 2017, 19:54

        @Stefanoxjx Worked fine for me... I used this code to test with qt 5.7 on linux:

        #include <QDateTime>
        #include <QDebug>
        
        int main(int ac, char **av)
        {
                QDateTime dt = QDateTime::currentDateTime();
                qDebug() << "date time is: " << dt.toTime_t();
                QDateTime dt2 = QDateTime::fromTime_t(dt.toTime_t());
                qDebug() << "dt2: " << dt2;
                return 0;
        }
        

        Output was as expected with the current local time and the converted time_t was correct with current local as well.

        My guess is you are getting a bad value from your UI control. No bug that I can find in Qt's QDateTime.

        S Offline
        S Offline
        Stefanoxjx
        wrote on 2 Jan 2017, 22:48 last edited by
        #3

        @ambershark
        Hello @ambershark and thanks for your help.
        I don't understand what appened, but the same code that did not work well, now it works fine.

        Stefano

        A 1 Reply Last reply 2 Jan 2017, 23:10
        0
        • S Stefanoxjx
          2 Jan 2017, 22:48

          @ambershark
          Hello @ambershark and thanks for your help.
          I don't understand what appened, but the same code that did not work well, now it works fine.

          Stefano

          A Offline
          A Offline
          ambershark
          wrote on 2 Jan 2017, 23:10 last edited by
          #4

          @Stefanoxjx Oh that's good it is working now... You may just have had a dirty build and after a rebuild things were "fixed". :)

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          0

          1/4

          2 Jan 2017, 18:23

          • Login

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