Deprecated: Array and string offset access syntax with curly braces is deprecated in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/init.php on line 542
====== 時間の扱い ======
----
#include
* time_t : 型。環境によるがlong int からのtypedefが多い? UNIX timeを格納するのに使う
* tm : 構造体。
* function
* time_t mktime( struct tm* st_time ) : tm をtime_t (UNIX time)に変換
* struct tm* localtime( const time_t *time ) : time_t から tm に変換(local timeとして)
* struct tm* gmtime( const time_t *time ) : time_t から tm に変換( UTCとして)
* size_t strftime( char* buf, size_t buflen, char* form, struct tm* st_time ) : tmを文字列に変換
* char *strptime(const char *buf, const char *format, struct tm *tm) : 文字列をtmに変換
time_t StartTime = 1490612400;
struct tm* tm_Start = localtime(&StartTime);
char buf[100];
strftime(buf, sizeof(buf), "%Y%m%d", tm_Start);// bufに指定したフォーマット(年月日)で渡す(->”20170327”)
struct tm tm_A;
char *TimeChar = "3/27/2017-20:00:00";
strptime(TimeChar, "%m/%d/%Y-%H:%M:%S", &tm_A);// TimeCharから指定したフォーマットで抜き出して、tm_Aに入れる
time_t time = mktime(&tm_A);// tm_A からUNIX timeを返す