獲取當(dāng)前系統(tǒng)本地時(shí)間,精確到毫秒的實(shí)例
實(shí)例如下:
#include <sys/timeb.h> #include <chrono> char* cur_time_c(char strDateTime[32]) { struct timeb tp_cur; ftime(&tp_cur); struct tm btm; #ifdef WIN32 localtime_s(&btm, &tp_cur.time); #else localtime_r(&tp_cur.time, &btm); #endif sprintf(strDateTime, "%04d-%02d-%02d %02d:%02d:%02d.%03d", btm.tm_year + 1900, btm.tm_mon + 1, btm.tm_mday, btm.tm_hour, btm.tm_min, btm.tm_sec, tp_cur.millitm); return strDateTime; } char* cur_time_cpp11(char strDateTime[32]) { static const std::chrono::hours = EIGHT_HOURS(8); auto nowLocalTimeCount = std::chrono::system_clock::now().time_since_epoch() + EIGHT_HOURS; std::chrono::hours now_h = std::chrono::duration_cast<std::chrono::hours>(nowLocalTimeCount); std::chrono::minutes now_m = std::chrono::duration_cast<std::chrono::minutes>(nowLocalTimeCount); std::chrono::seconds now_s = std::chrono::duration_cast<std::chrono::seconds>(nowLocalTimeCount); std::chrono::milliseconds now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(nowLocalTimeCount); sprintf(strDateTime, "%02d:%02d:%02d.%03d", now_h % 24, now_m % 60, now_s % 60, now_ms % 1000); return strDateTime; }
以上這篇獲取當(dāng)前系統(tǒng)本地時(shí)間,精確到毫秒的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持我們。
欄 目:C語言
下一篇:C++結(jié)構(gòu)體struct和類class區(qū)別詳解
本文標(biāo)題:獲取當(dāng)前系統(tǒng)本地時(shí)間,精確到毫秒的實(shí)例
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1042.html
您可能感興趣的文章
- 01-10Linux C 獲取進(jìn)程退出值的實(shí)現(xiàn)代碼
- 01-10解析Linux下的時(shí)間函數(shù):設(shè)置以及獲取時(shí)間的方法
- 01-10DHCP:解析開發(fā)板上動(dòng)態(tài)獲取ip的2種實(shí)現(xiàn)方法詳解
- 01-10基于linux下獲取時(shí)間函數(shù)的詳解
- 01-10linux c 獲取本機(jī)公網(wǎng)IP的實(shí)現(xiàn)方法
- 01-10基于Linux系統(tǒng)調(diào)用--getrlimit()與setrlimit()函數(shù)的方法
- 01-10用c 獲取文件MD5值的實(shí)現(xiàn)方法
- 01-10在vs2010中,輸出當(dāng)前文件路徑與源文件當(dāng)前行號(hào)的解決方法
- 01-10linux c 獲得當(dāng)前進(jìn)程的進(jìn)程名和執(zhí)行路徑(示例)
- 01-10使用C語言中的time函數(shù)獲取系統(tǒng)時(shí)間


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對(duì)數(shù)函數(shù)的表達(dá)式 c語言中對(duì)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機(jī)閱讀
- 01-10delphi制作wav文件的方法
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10C#中split用法實(shí)例總結(jié)
- 04-02jquery與jsp,用jquery