日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UTC时间戳-时间字符串之间互相转化

發布時間:2024/4/11 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UTC时间戳-时间字符串之间互相转化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1,標準時間準換成時間戳

int standard_to_stamp(char *str_time)??
{??
??????? struct tm stm;??
??????? int iY, iM, iD, iH, iMin, iS;??

??????? memset(&stm,0,sizeof(stm));??
??????? iY = atoi(str_time);??
??????? iM = atoi(str_time+5);??
??????? iD = atoi(str_time+8);??
??????? iH = atoi(str_time+11);??
??????? iMin = atoi(str_time+14);??
??????? iS = atoi(str_time+17);??

??????? stm.tm_year=iY-1900;??
??????? stm.tm_mon=iM-1;??
??????? stm.tm_mday=iD;??
??????? stm.tm_hour=iH;??
??????? stm.tm_min=iMin;??
??????? stm.tm_sec=iS;??

??????? /*printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);*/?? //標準時間格式例如:2016:08:02 12:12:30
??????? return (int)mktime(&stm);??
}??

2,時間戳轉換成標準時間

typedef struct times
{
??????? int Year;
??????? int Mon;
??????? int Day;
??????? int Hour;
??????? int Min;
??????? int Second;
}Times;

Times stamp_to_standard(int stampTime)
{
??????? time_t tick = (time_t)stampTime;
??????? struct tm tm;?
??????? char s[100];
??????? Times standard;

??????? //tick = time(NULL);
??????? tm = *localtime(&tick);
??????? strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);
??????? printf("%d: %s\n", (int)tick, s);?


??????? standard.Year = atoi(s);
??????? standard.Mon = atoi(s+5);
??????? standard.Day = atoi(s+8);
??????? standard.Hour = atoi(s+11);
??????? standard.Min = atoi(s+14);
??????? standard.Second = atoi(s+17);
?? ?
??????? return standard;
}

3,如何獲取系統標準時間

time_t rawtime ;?

struct tm * timeinfo;?

time ( &rawtime );?

timeinfo = localtime ( &rawtime );?

其中:

int Year = timeinfo->tm_year+1900;

int Mon = timeinfo->tm_mon+1;

其余日,時,分,秒都不變。


4,如何獲取系統當前時間戳

?time_t now;?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?int unixTime = (int)time(&now);

總結

以上是生活随笔為你收集整理的UTC时间戳-时间字符串之间互相转化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。