Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert total seconds to date time format

Convert total seconds to date time format

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Arif Liminto
    wrote on last edited by
    #1

    HI, I am doing visual c++ 2003, and I want to ask about how to convert the data type format ( TotalSeconds) to date format, I know how to convert from date format to total seconds but how to convert in the reverse way, I don't know this is the way that I convert from date format to total seconds Ctime Now = CTime::GetCurrentTime(); CTime UCT(0); CTimeSpan Diff = Now - UCT; return Diff.GetTotalSeconds(); but how to convert in the reverse way I would be grateful if you guys can help me :) Regards, Arif Liminto

    L _ A 3 Replies Last reply
    0
    • A Arif Liminto

      HI, I am doing visual c++ 2003, and I want to ask about how to convert the data type format ( TotalSeconds) to date format, I know how to convert from date format to total seconds but how to convert in the reverse way, I don't know this is the way that I convert from date format to total seconds Ctime Now = CTime::GetCurrentTime(); CTime UCT(0); CTimeSpan Diff = Now - UCT; return Diff.GetTotalSeconds(); but how to convert in the reverse way I would be grateful if you guys can help me :) Regards, Arif Liminto

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      arifliminto86 wrote:

      but how to convert in the reverse way

      I am not sure that I understand your question but I believe that you are asking how to convert a 64 bit integer containing CTime total seconds back into a CTime object. If this is what your looking for then perhaps the following code will help.CTime tNow = CTime::GetCurrentTime(); OutputDebugString(tNow.Format(_T("Current Time: %A, %B %d, %Y\n"))); LONGLONG i64TotalSeconds = tNow.GetTime(); //seconds since January 1, 1970 CTime tBack(i64TotalSeconds); OutputDebugString(tBack.Format(_T("Converted Time: %A, %B %d, %Y\n")));
      Best Wishes, -David Delaune

      1 Reply Last reply
      0
      • A Arif Liminto

        HI, I am doing visual c++ 2003, and I want to ask about how to convert the data type format ( TotalSeconds) to date format, I know how to convert from date format to total seconds but how to convert in the reverse way, I don't know this is the way that I convert from date format to total seconds Ctime Now = CTime::GetCurrentTime(); CTime UCT(0); CTimeSpan Diff = Now - UCT; return Diff.GetTotalSeconds(); but how to convert in the reverse way I would be grateful if you guys can help me :) Regards, Arif Liminto

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        Store your number of seconds in a time_t variable and pass it to one of the functions that takes a time_t (or time_t *); then process the result.Eg

        int main ()
        {
          time_t rawtime;
          struct tm * timeinfo;
        
          time ( &rawtime ); // here rawtime is the time in seconds
          timeinfo = localtime ( &rawtime );
          printf ( "The current date/time is: %s", asctime (timeinfo) );
          
          return 0;
        }
        

        Hope it helps

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        1 Reply Last reply
        0
        • A Arif Liminto

          HI, I am doing visual c++ 2003, and I want to ask about how to convert the data type format ( TotalSeconds) to date format, I know how to convert from date format to total seconds but how to convert in the reverse way, I don't know this is the way that I convert from date format to total seconds Ctime Now = CTime::GetCurrentTime(); CTime UCT(0); CTimeSpan Diff = Now - UCT; return Diff.GetTotalSeconds(); but how to convert in the reverse way I would be grateful if you guys can help me :) Regards, Arif Liminto

          A Offline
          A Offline
          Arif Liminto
          wrote on last edited by
          #4

          Thanks Guys, It works

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups