Skip to content

Instantly share code, notes, and snippets.

@Restoration
Created December 4, 2019 17:03
Show Gist options
  • Select an option

  • Save Restoration/572f2ededbb8c2ae26a80ae09bbdb5c7 to your computer and use it in GitHub Desktop.

Select an option

Save Restoration/572f2ededbb8c2ae26a80ae09bbdb5c7 to your computer and use it in GitHub Desktop.
struct tm {
int tm_sec; /* 秒 (0-60) */
int tm_min; /* 分 (0-59) */
int tm_hour; /* 時間 (0-23) */
int tm_mday; /* 月内の日付 (1-31) */
int tm_mon; /* 月 (0-11) */
int tm_year; /* 年 - 1900 */
int tm_wday; /* 曜日 (0-6, 日曜 = 0) */
int tm_yday; /* 年内通算日 (0-365, 1 月 1 日 = 0) */
int tm_isdst; /* 夏時間 */
};
#include <iostream>
#include <time.h>
int main(){
struct tm tm;
const char *dayofweek[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
time_t t = time(NULL);
localtime_r(&t, &tm);
printf("%04d/%02d/%02d %s %02d:%02d:%02d\n",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
dayofweek[tm.tm_wday], tm.tm_hour, tm.tm_min, tm.tm_sec
);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment