最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言實(shí)現(xiàn)字符轉(zhuǎn)unix時(shí)間戳的簡單實(shí)例

 更新時(shí)間:2016年06月13日 16:50:06   投稿:jingxian  
下面小編就為大家?guī)硪黄狢語言實(shí)現(xiàn)字符轉(zhuǎn)unix時(shí)間戳的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

C語言實(shí)現(xiàn)字符轉(zhuǎn)unix時(shí)間戳,需要先轉(zhuǎn)成tm類型,再得到它的Unix時(shí)間戳。附上實(shí)現(xiàn)代碼:

#include <stdio.h>
#include <time.h>
int strtotime(char datetime[])
{
struct tm tm_time;
int unixtime;
strptime(datetime, "%Y-%m-%d %H:%M:%S", &tm_time);

unixtime = mktime(&tm_time);
return unixtime;
}


另附上幾個(gè)時(shí)間相關(guān)的函數(shù),做個(gè)筆記:

//當(dāng)前時(shí)間


char* get_curr_time()
{
char* strtime = (char *)malloc(sizeof(char)*20);
memset(strtime, 0, sizeof(char)*20);
time_t now;
time(&now);
strftime(strtime, 20, "%Y-%m-%d %H:%M:%S", gmtime(&now));
printf("Info: current time %s\n", strtime);
return strtime;
}


//當(dāng)前時(shí)間的unix時(shí)間戳


int get_curr_unixtime(void)
{
time_t now;
int unixtime = time(&now);
return unixtime;
}


//字符轉(zhuǎn)unix時(shí)間戳


int strtotime(char datetime[])
{
struct tm tm_time;
int unixtime;
strptime(datetime, “%Y-%m-%d %H:%M:%S”, &tm_time);

unixtime = mktime(&tm_time);
return unixtime;
}

以上這篇C語言實(shí)現(xiàn)字符轉(zhuǎn)unix時(shí)間戳的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

莱西市| 屯昌县| 吴川市| 曲阳县| 寻乌县| 高陵县| 乌拉特中旗| 阿拉尔市| 汾西县| 临武县| 涪陵区| 日土县| 台江县| 和政县| 德令哈市| 房产| 玛沁县| 通江县| 安阳市| 获嘉县| 长汀县| 漳平市| 沂南县| 南京市| 勃利县| 年辖:市辖区| 彭阳县| 个旧市| 茂名市| 鄯善县| 长岭县| 青河县| 宾阳县| 嘉祥县| 渭南市| 新蔡县| 永兴县| 犍为县| 新野县| 兴海县| 太湖县|