Results 1 to 3 of 3

Thread: QDateTime GMT add sec. or - sec. from locale time....

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDateTime GMT add sec. or - sec. from locale time....

    The server send my a date format evry time on GMT null format... Greenw...
    "Wed, 07 Feb 2007 18:44:19 GMT"
    to append one one H i make so...
    dateTime2.addSecs(3600); /* by hand ....*/
    but how i can discovery a calculable local date.... +1 or -1

    muss i build a switsch for evry 24 world H. time....

    I like Unix time format to display human readable time and to see diff from localfile lastmod time.... (QFileInfo)

    Qt Code:
    1. /* grab remote server gmt time to check localfile lastmod update or not */
    2.  
    3.  
    4. uint MailTimeString( QString indate )
    5.  
    6. {
    7.  
    8. /* incomming format Wed, 07 Feb 2007 18:44:19 GMT*/
    9.  
    10. /* or mail rtf Date format! http://www.faqs.org/rfcs/rfc788.html */
    11.  
    12. indate.replace("Date:","");
    13.  
    14. indate.trimmed();
    15.  
    16. QLocale::setDefault(QLocale::C); /* on comment out time is bad */
    17.  
    18. QStringList sdate = indate.split(" ");
    19.  
    20. if (sdate.size() != 6) {
    21.  
    22. return QTime_Null(); /* time current uint format */
    23.  
    24. }
    25.  
    26. sdate.removeFirst();
    27.  
    28. sdate.removeLast();
    29.  
    30. QString reformat = sdate.join(" ");
    31.  
    32. QDateTime dateTime2 = QDateTime::fromString(reformat,"dd MMM yyyy HH:mm:ss");
    33.  
    34. QDateTime dateTime3 = dateTime2.addSecs(3600); /* GMT +1 switzerland */
    35.  
    36. QLocale::system(); /* on comment out time is bad */
    37.  
    38. return dateTime3.toTime_t();
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDateTime GMT add sec. or - sec. from locale time....

    I must admit that I have not 100% understood you question.

    But If you would like to convert a GMT datetime to a local datetime:
    Qt Code:
    1. QDateTime gmtDateTime = parseDateTime(XXXXX);
    2. gmtDateTime.setTimeSpec(Qt::UTC);
    3. QDateTime localDateTime = gmtDateTime.toLocalTime();
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to camel for this useful post:

    patrik08 (20th February 2007), tpf80 (8th June 2007)

  4. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateTime GMT add sec. or - sec. from locale time....

    Oh.... yes only this simple "Qt::UTC" && .toLocalTime(); solve the date problem.... Tanks...

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 16:15
  2. Qt4 and system locale
    By L.Marvell in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2007, 14:00
  3. Replies: 1
    Last Post: 30th June 2006, 06:24
  4. QDateTime without Day
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2006, 12:42
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 16:48

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.