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
ja:cpp:time [GiriWiki]

ユーザ用ツール

サイト用ツール


ja:cpp:time

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
ja:cpp:time [2017/03/27 11:09]
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 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_A;   struct tm tm_A;
   char *TimeChar = "​3/​27/​2017-20:​00:​00";​   char *TimeChar = "​3/​27/​2017-20:​00:​00";​
-  strptime(TimeString, "​%m/​%d/​%Y-%H:​%M:​%S",​ &​tm_A);​ +  strptime(TimeChar, "​%m/​%d/​%Y-%H:​%M:​%S",​ &tm_A);// TimeCharから指定したフォーマットで抜き出して、tm_Aに入れる 
-  time_t time = mktime(&​tm_A);​+  time_t time = mktime(&​tm_A);​// tm_A からUNIX timeを返す
 </​code>​ </​code>​
ja/cpp/time.1490612981.txt.gz · 最終更新: 2017/03/27 11:09 by kota