当前位置:网站首页>Time processing in C language (conversion between string and timestamp)

Time processing in C language (conversion between string and timestamp)

2022-06-12 13:29:00 Boring ah le

C Time processing in language ( String and timestamp conversion )


// One 、 Convert... To time stamp 

//strfmt

void metis_strftime(time_t t, char *pcTime)
{
    
  struct tm *tm_t;
  tm_t = localtime(&t);
  strftime(pcTime,128,"%F %T",tm_t);
}


// Two 、 Convert a string to a timestamp 

long metis_strptime(char *str_time)
{
    
  struct tm stm;  
  strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm);
  long t = mktime(&stm);
  return t;
}
原网站

版权声明
本文为[Boring ah le]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010516317243.html