User Tools

Site Tools


programming:cpp:unixtime

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:cpp:unixtime [2022/05/05 07:45]
odagawa created
programming:cpp:unixtime [2022/09/12 08:38] (current)
odagawa
Line 14: Line 14:
  
   // int64_t unixtime_i = 1651736619; // 2022-05-05 16:43:39   // int64_t unixtime_i = 1651736619; // 2022-05-05 16:43:39
-  // time_t now = (time_t)unixttime_t;+  // time_t now = (time_t)unixtime_t;
      
   time_t now = std::time(nullptr); // 現在時刻   time_t now = std::time(nullptr); // 現在時刻
-  tm *tm_event = localtime(&unixtime); // 現地時間に直す+  tm *tm_event = localtime(&now); // 現地時間に直す
      
   int year = tm_event->tm_year + 1900; // tm_year は 1900 年始まり   int year = tm_event->tm_year + 1900; // tm_year は 1900 年始まり
   int month = tm_event->tm_mon + 1; // tm_mon は 0 始まり   int month = tm_event->tm_mon + 1; // tm_mon は 0 始まり
   int day = tm_event->tm_mday;   int day = tm_event->tm_mday;
 +  
 +  std::cout << year << "/" << month << "/" << day <<std::endl;
  
   std::exit(0);   std::exit(0);
Line 29: Line 31:
 </code> </code>
  
-''tm'' は以下のよう定義+''tm'' は以下のよう定義されている 
 +<code cpp> 
 +struct tm { 
 +    int  tm_sec;    /* seconds after the minute [0-60] */ 
 +    int  tm_min;    /* minutes after the hour [0-59] */ 
 +    int  tm_hour;   /* hours since midnight [0-23] */ 
 +    int  tm_mday;   /* day of the month [1-31] */ 
 +    int  tm_mon;    /* months since January [0-11] */ 
 +    int  tm_year;   /* years since 1900 */ 
 +    int  tm_wday;   /* days since Sunday [0-6] */ 
 +    int  tm_yday;   /* days since January 1 [0-365] */ 
 +    int  tm_isdst;  /* Daylight Savings Time flag */ 
 +    long tm_gmtoff; /* offset from CUT in seconds */ 
 +    char *tm_zone;  /* timezone abbreviation */ 
 +}; 
 +</code> 
 + 
 +[[https://tool.konisimple.net/date/unixtime|Unixtime 変換ツール]]
programming/cpp/unixtime.1651736743.txt.gz · Last modified: 2022/05/05 07:45 by odagawa