C++ strptime 和strptime函数的使用方式

时间标签(timestamp)的格式为RFC3339格式。

strptime  和strptime函数

 

#include       /* puts, printf */
#include        /* time_t, struct tm, time, localtime */
#include 
using namespace std;
int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
char buffer [80];
  time (&rawtime);
  timeinfo = localtime (&rawtime);
 int length= strftime (buffer,80,"%Y-%m-%dT%H:%M:%SZ\n",timeinfo);
 
  
  printf ("timestamp: %.*s",length,buffer);

  return 0;
}

strptime 函数将字符串转换成 tm 结构

#include 
       #include 
       #include 
       #include 
using namespace std;
       int
       main(void)
       {
           struct tm *timeinfo;
           char buffer[80];
           memset( timeinfo, 0, sizeof(struct tm));
           strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S",  timeinfo);
            int length= strftime (buffer,80,"%Y-%m-%dT%H:%M:%SZ\n",timeinfo);
            printf ("timestamp: %.*s",length,buffer);
           exit(EXIT_SUCCESS);
       }

localtime 和mktime 函数

mktime 将tm 结构转换成 time_t

localtime 将time_t 转换成 tm结构时间

gmtime 函数 Convert time_t to tm as UTC time

你可能感兴趣的:(C++)