Results 1 to 5 of 5

Thread: QCustomPlot using timestamp to set Date along one axis

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QCustomPlot using timestamp to set Date along one axis

    The first column looks like a date formatted as a YYYYMMDD string.

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    bandito (5th March 2016)

  3. #2
    Join Date
    Mar 2016
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: QCustomPlot using timestamp to set Date along one axis

    Quote Originally Posted by anda_skoa View Post
    The first column looks like a date formatted as a YYYYMMDD string.

    Cheers,
    _
    You are correct. Thanks!

    I came up with this function to convert the QString to a double value timestamp.

    Qt Code:
    1. double timeStamp(QString qs){
    2. char tempDate[10];
    3. memcpy(tempDate, qs.toStdString().c_str(), 10);
    4. char date[] = " ";
    5. date[0] = tempDate[0];
    6. date[1] = tempDate[1];
    7. date[2] = tempDate[2];
    8. date[3] = tempDate[3];
    9. date[4] = '\0';
    10. date[5] = tempDate[4];
    11. date[6] = tempDate[5];
    12. date[7] = '\0';
    13. date[8] = tempDate[6];
    14. date[9] = tempDate[7];
    15.  
    16. struct tm tmdate = {0};
    17. tmdate.tm_year = atoi(&date[0]) - 1900;
    18. tmdate.tm_mon = atoi(&date[5]) - 1;
    19. tmdate.tm_mday = atoi(&date[8]);
    20. time_t t = mktime( &tmdate );
    21.  
    22. double actual_time_sec = difftime(t,0);
    23.  
    24. return actual_time_sec;
    25. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCustomPlot using timestamp to set Date along one axis

    In one line :
    Qt Code:
    1. double timeStamp(QString qs){
    2. return QDateTime(QDate::fromString(qs,"yyyyMMdd"),QTime(0,0,0)).toTime_t();
    3. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lesiok for this useful post:

    bandito (5th March 2016)

  6. #4
    Join Date
    Mar 2016
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: QCustomPlot using timestamp to set Date along one axis

    Quote Originally Posted by Lesiok View Post
    In one line :
    Qt Code:
    1. double timeStamp(QString qs){
    2. return QDateTime(QDate::fromString(qs,"yyyyMMdd"),QTime(0,0,0)).toTime_t();
    3. }
    To copy to clipboard, switch view to plain text mode 
    Wow that's sexy. Thanks!

Similar Threads

  1. Replies: 3
    Last Post: 1st February 2016, 08:04
  2. KDChart Date-time Axis howto?
    By galrub in forum Qt Programming
    Replies: 0
    Last Post: 15th October 2012, 11:36
  3. Qwt X-Axis with Date, correct distance
    By Lykanthropie in forum Qwt
    Replies: 5
    Last Post: 5th January 2012, 18:22
  4. Date Scale for X-Axis
    By mishani99 in forum Qwt
    Replies: 3
    Last Post: 6th September 2011, 11:40
  5. Time/Date Axis
    By sigger in forum Qwt
    Replies: 12
    Last Post: 1st May 2011, 09:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.