Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is there any function is avalible in QT/c++ that we pass selected date and time as a string/ time_t structure a we get time in seconds since epoch ?

Is there any function is avalible in QT/c++ that we pass selected date and time as a string/ time_t structure a we get time in seconds since epoch ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.4k 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.
  • T Offline
    T Offline
    TM9412
    wrote on last edited by
    #1

    i want to pass date and time as string or i will fill the date and time in time_t structure
    defined in <time.h> as follows:

           struct tm {
               int tm_sec;    /* Seconds (0-60) */
               int tm_min;    /* Minutes (0-59) */
               int tm_hour;   /* Hours (0-23) */
               int tm_mday;   /* Day of the month (1-31) */
               int tm_mon;    /* Month (0-11) */
               int tm_year;   /* Year - 1900 */
               int tm_wday;   /* Day of the week (0-6, Sunday = 0) */
               int tm_yday;   /* Day in the year (0-365, 1 Jan = 0) */
               int tm_isdst;  /* Daylight saving time */
           };
    

    after that i want time of that date and time in seconds since epoch .

    if i used this function so i get current time in seconds since epoch

    qint64 QDateTime::toSecsSinceEpoch() const
    Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).

    T 1 Reply Last reply
    0
    • T TM9412

      i want to pass date and time as string or i will fill the date and time in time_t structure
      defined in <time.h> as follows:

             struct tm {
                 int tm_sec;    /* Seconds (0-60) */
                 int tm_min;    /* Minutes (0-59) */
                 int tm_hour;   /* Hours (0-23) */
                 int tm_mday;   /* Day of the month (1-31) */
                 int tm_mon;    /* Month (0-11) */
                 int tm_year;   /* Year - 1900 */
                 int tm_wday;   /* Day of the week (0-6, Sunday = 0) */
                 int tm_yday;   /* Day in the year (0-365, 1 Jan = 0) */
                 int tm_isdst;  /* Daylight saving time */
             };
      

      after that i want time of that date and time in seconds since epoch .

      if i used this function so i get current time in seconds since epoch

      qint64 QDateTime::toSecsSinceEpoch() const
      Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).

      T Offline
      T Offline
      TM9412
      wrote on last edited by
      #2

      @TM9412

      qint64 QDateTime::secsTo(const QDateTime &other) const
      Returns the number of seconds from this datetime to the other datetime. If the other datetime is earlier than this datetime, the value returned is negative.

      Before performing the comparison, the two datetimes are converted to Qt::UTC to ensure that the result is correct if daylight-saving (DST) applies to one of the two datetimes but not the other.

      Returns 0 if either datetime is invalid.

      Example:

      QDateTime now = QDateTime::currentDateTime();
      QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
      qDebug("There are %d seconds to Christmas", now.secsTo(xmas));

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MirkoV
        wrote on last edited by
        #3

        QDateTime class has all you need.

        Use "fromString" to retrieve a QDateTime and toSecsSinceEpoch to get the secs from epoch

        1 Reply Last reply
        3

        • Login

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