この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
ja:cpp:time [2017/03/27 11:03] kota |
ja:cpp:time [2017/03/27 12:09] (現在) kota |
||
|---|---|---|---|
| ライン 5: | ライン 5: | ||
| #include <ctime> | #include <ctime> | ||
| + | * 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に変換 | ||
| <code cpp> | <code cpp> | ||
| - | time_t StartTime | + | time_t StartTime = 1490612400; |
| struct tm* tm_Start = localtime(&StartTime); | struct tm* tm_Start = localtime(&StartTime); | ||
| - | Char_t buf[100]; | + | char buf[100]; |
| - | strftime(buf, sizeof(buf), "%Y%m%d", tm_Start); | + | strftime(buf, sizeof(buf), "%Y%m%d", tm_Start);// bufに指定したフォーマット(年月日)で渡す(->”20170327”) |
| - | + | ||
| - | struct tm tm_SpillLengthTime; | + | struct tm tm_A; |
| - | TString SpillLengthTime; | + | char *TimeChar = "3/27/2017-20:00:00"; |
| - | + | strptime(TimeChar, "%m/%d/%Y-%H:%M:%S", &tm_A);// TimeCharから指定したフォーマットで抜き出して、tm_Aに入れる | |
| - | strptime(SpillLengthTime, "%m/%d/%Y-%H:%M:%S", &tm_SpillLengthTime); | + | time_t time = mktime(&tm_A);// tm_A からUNIX timeを返す |
| - | time_t time = mktime(&tm_SpillLengthTime); | + | |
| </code> | </code> | ||