C++时间处理

来源:互联网 发布:保险销售人员网络教育 编辑:程序博客网 时间:2024/06/14 07:31
#include <time.h>//get calendar timetime_t t_local_time;time_t t_gm_time;time(&t_local_time);t_gm_time = time(NULL);//to struct tm//formal(星期几 月份 日期 时:分:秒 年\n\0)  //e.g:Wed Jan 02 02:03:55 1980\n\0 )//gmtime和localtime的结果放在STL静态区,调用任何一个都会修改值,因此这里不用pointstruct tm tm_gm_time = *gmtime(&t_gm_time);struct tm tm_local_time = *localtime(&t_local_time);char* cc_time = ctime( &t_local_time);char* formal_local_time = asctime(&tm_local_time);char* formal_gm_time = asctime(&tm_gm_time);//strDate and strTimechar temp_date[24];char temp_time[24];char* str_Date = _strdate(temp_date);//结果放在temp_datechar* str_Time = _strtime(temp_time);//结果放在temp_time//diff time double diff_time = difftime(t_local_time, t_gm_time);//time use//srandsrand((unsigned)time(NULL));int rand_ = rand();
原创粉丝点击