| 2021.02.25 追記
| こういった操作は,ラップして置いた方がわかりやすい.
| 例:
https://admiswalker.github.io/sstdref/src/time/time.html
#include <time.h>
struct tm date;
date.tm_year = year - 1900;
date.tm_mon = mon - 1;
date.tm_mday = day;
date.tm_hour = 0;
date.tm_min = 0;
date.tm_sec = 0;
date.tm_yday = 0; // 通日
// [time_t unixtime;] to [struct tm date;] (スレッドセーフでない)
date = *localtime(&unixtime); // 地方時に変換される.
date = *gmtime(&unixtime);
// [time_t unixtime;] to [struct tm date;] (直接構造体へ渡す場合) (スレッドセーフ)
gmtime_r((time_t*)&unixtime,(struct tm*)&date); //GMT
localtime_r((struct tm*)&unixtime, (time_t*)&date); //こちらで設定すると、システムの示すローカル時間となる。
#ifdef _WIN32
#define gmtime_r(time_t_in,tm_out) gmtime_s((tm_out),(time_t_in))
#endif
// [struct tm date;] to [time_t unixtime;]
time_t unixtime = mktime(date);
time_t unixtime = timegm(&date); // 非標準関数
time_t unixtime = timelocal(&date); // 非標準関数
#ifdef _WIN32
#define timegm _mkgmtime
#endif
How to print struct tm.
struct tm tm;
/* Set tm to the correct time */
char s[20]; /* strlen("2009-08-10 18:17:54") + 1 */
strftime(s, 20, "%F %H:%M:%S", &tm);
参考文献:
https://msdn.microsoft.com/ja-jp/library/a442x3ye.aspx
https://linuxjm.osdn.jp/html/LDP_man-pages/man3/ctime.3.html
https://linuxjm.osdn.jp/html/LDP_man-pages/man3/timegm.3.html
https://stackoverflow.com/questions/3673226/how-to-print-time-in-format-2009-08-10-181754-811