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

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

C++时间标准库时间time

發(fā)布時(shí)間:2023/12/13 综合教程 23 生活家
生活随笔 收集整理的這篇文章主要介紹了 C++时间标准库时间time 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自:http://www.cnblogs.com/yukaizhao/archive/2011/04/29/cpp_time_system_time.html (玉開(kāi))

C++標(biāo)準(zhǔn)庫(kù)中的時(shí)間需要引用time.h,可以取的本地時(shí)間或者格林威治時(shí)間,只能精確到秒

#include <iostream>
 
/*包含time頭文件*/
#include <time.h>
 
 
using namespace std;
 
int main()
{
    //time_t是long類(lèi)型,精確到秒,是當(dāng)前時(shí)間和1970年1月1日零點(diǎn)時(shí)間的差
    const time_t t = time(NULL);
 
    cout<<"current time is "<<t<<endl;
 
    /*本地時(shí)間:日期,時(shí)間 年月日,星期,時(shí)分秒*/
    struct tm* current_time = localtime(&t);
    printf("current year is %d;current month is %d;current date of month is %d
",
        1900 + current_time->tm_year,
        1 + current_time->tm_mon/*此month的范圍為0-11*/,
        current_time->tm_mday);
 
    printf("current day of year is %d;current day in week is %d
",
        current_time->tm_yday,/*當(dāng)前日期是今年的第多少天[0,365] */
        current_time->tm_wday/*days since Sunday - [0,6] */);
 
    printf("time part %d:%d:%d 
",
        current_time->tm_hour,
        current_time->tm_min,
        current_time->tm_sec);
 
    printf("	本地時(shí)間:%d-%d-%d %d:%d:%d
",
        current_time->tm_year + 1900,
        current_time->tm_mon + 1,
        current_time->tm_mday,
        current_time->tm_hour,
        current_time->tm_min,
        current_time->tm_sec);
 
    /*格林威治時(shí)間*/
    struct tm* current_gmtime = gmtime(&t);
 
    printf("格林威治時(shí)間:%d-%d-%d %d:%d:%d
",
        current_gmtime->tm_year + 1900,
        current_gmtime->tm_mon + 1,
        current_gmtime->tm_mday,
        current_gmtime->tm_hour,
        current_gmtime->tm_min,
        current_gmtime->tm_sec);
 
 
    system("pause");
    return 0;
}

  

總結(jié)

以上是生活随笔為你收集整理的C++时间标准库时间time的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。