Results 1 to 4 of 4

Thread: Time convertion

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Time convertion

    Hi,

    please any one give some way to convert time from Local to UTC and UTC to Local in Qt.
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time convertion


  3. The following user says thank you to jacek for this useful post:

    rajeshs (5th June 2008)

  4. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time convertion

    actually i tried with setTimeSpec() function, but it is not conveting time from UTC to LocalTime.
    Thanks,
    Rajesh.S

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Time convertion

    setTimeSpec() doesn't do the conversion, it only tells Qt that the date is in UTC. You also need to call toLocalTime(), toUTC() or toTimeSpec().
    Qt Code:
    1. QDateTime d( QDate( 2008, 6, 5 ), QTime( 12, 0 ) );
    2. d.setTimeSpec( Qt::UTC );
    3. qDebug() << d << d.toLocalTime();
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QDateTime d( QDate( 2008, 6, 5 ), QTime( 12, 0 ), QT::UTC );
    2. qDebug() << d << d.toLocalTime();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. file time stamp preservation
    By baray98 in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2008, 00:13
  2. Replies: 1
    Last Post: 1st February 2008, 18:55
  3. to set date and time in the file info of two days back
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 16:54
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15: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.