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

時間の扱い


#include <ctime>

  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を返す