中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C++時(shí)間標(biāo)準(zhǔn)庫(kù)時(shí)間time和系統(tǒng)時(shí)間的使用

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

1. 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\r\n",
        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\r\n",
        current_time->tm_yday,/*當(dāng)前日期是今年的第多少天[0,365] */
        current_time->tm_wday/*days since Sunday - [0,6] */);

    printf("time part %d:%d:%d \r\n",
        current_time->tm_hour,
        current_time->tm_min,
        current_time->tm_sec);

    printf("\t本地時(shí)間:%d-%d-%d %d:%d:%d\r\n",
        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\r\n",
        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;
}

2. 系統(tǒng)時(shí)間 SYSTEMTIME 使用時(shí)要引用windows.h,可以精確到毫秒級(jí)別
#include <iostream>
#include <Windows.h>

int main(){
    //聲明變量
    SYSTEMTIME sys_time;

    //將變量值設(shè)置為本地時(shí)間
    GetLocalTime( &sys_time );

    //輸出時(shí)間
    printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n",sys_time.wYear,
        sys_time.wMonth,
        sys_time.wDay,
        sys_time.wHour,
        sys_time.wMinute, 
        sys_time.wSecond,
        sys_time.wMilliseconds,
        sys_time.wDayOfWeek);

    system("time");

    system("pause");
    return 0;
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:生成高品質(zhì)小空間的縮略圖C#代碼

下一篇:android讀取xml