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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. UTC time Clock and Local time Clock?

UTC time Clock and Local time Clock?

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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.
  • Y Offline
    Y Offline
    Yonggoo
    wrote on last edited by
    #1

    Hi, I am making a program to print out both UTC time and local time. But, I am having the same time. Do I have to save UTC time before 'ptrLocalTime = localtime(&localtimer);'? /* This program shows UTC time, and local time in 00:00:00 */ #include #include #define PST (-8) //Pacific Time Zone #define CST (-6) //Central Time Zone int main () { time_t timer; time_t localtimer; tm* ptrUTC; tm* ptrLocalTime; time ( &timer ); //Set timer to the number of seconds elapsed since 00:00 hours, //Jan 1, 1970 UTC from the system clock. time(&localtimer); ptrUTC = gmtime ( &timer ); //Converts timer to tm structure adjusting to UTC //(formerly known as GMT) timezone. ptrLocalTime = localtime(&localtimer); printf ("UTC Time: %2d:%02d:%02d\n", ptrUTC->tm_hour, ptrUTC->tm_min, ptrUTC->tm_sec); printf ("Locat time : %2d:%02d:%02d\n", ptrLocalTime->tm_hour, ptrLocalTime->tm_min, ptrLocalTime->tm_sec); return 0; } Please! Yonggoo

    A 1 Reply Last reply
    0
    • Y Yonggoo

      Hi, I am making a program to print out both UTC time and local time. But, I am having the same time. Do I have to save UTC time before 'ptrLocalTime = localtime(&localtimer);'? /* This program shows UTC time, and local time in 00:00:00 */ #include #include #define PST (-8) //Pacific Time Zone #define CST (-6) //Central Time Zone int main () { time_t timer; time_t localtimer; tm* ptrUTC; tm* ptrLocalTime; time ( &timer ); //Set timer to the number of seconds elapsed since 00:00 hours, //Jan 1, 1970 UTC from the system clock. time(&localtimer); ptrUTC = gmtime ( &timer ); //Converts timer to tm structure adjusting to UTC //(formerly known as GMT) timezone. ptrLocalTime = localtime(&localtimer); printf ("UTC Time: %2d:%02d:%02d\n", ptrUTC->tm_hour, ptrUTC->tm_min, ptrUTC->tm_sec); printf ("Locat time : %2d:%02d:%02d\n", ptrLocalTime->tm_hour, ptrLocalTime->tm_min, ptrLocalTime->tm_sec); return 0; } Please! Yonggoo

      A Offline
      A Offline
      Arvind Bharti
      wrote on last edited by
      #2

      The gmtime, mktime, and localtime functions use the same single, statically allocated structure to hold their results. Each call to one of these functions destroys the result of any previous call. Please check the address stored in ptrLocalTime and ptrUTC. Both are same. So you have to make a copy before calling another function.

      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