欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

解析Linux下的時(shí)間函數(shù):設(shè)置以及獲取時(shí)間的方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

一、時(shí)間函數(shù)

復(fù)制代碼 代碼如下:

time_t time(time_t *t);
char *asctime(const struct tm *tm);
char *asctime_r(const struct tm *tm, char *buf);
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
struct tm *gmtime(const time_t *timep); //獲取的為英國時(shí)間
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep);      //獲取的為本地時(shí)間,注意與英國時(shí)間的區(qū)別。
struct tm *localtime_r(const time_t *timep, struct tm *result);
time_t mktime(struct tm *tm);
double difftime(time_t time1, time_t time0);
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);

二、設(shè)置和獲取時(shí)間
復(fù)制代碼 代碼如下:

#include <stdio.h>
#include <time.h>

int main(void)
{
time_t t1;
time_t t2;
struct tm *my_tm;
char buf[128] = {0};

//自Epoch (00:00:00 UTC, January 1,1970)的秒數(shù)
t1 = time(&t1);
printf("%d\n", t1);  //1355905754
t2 = time(&t2);

sleep(1);
printf("%lf\n", difftime(t2, t1));  //t1,t2相差:1.000000,有時(shí)候可以用這個(gè)函數(shù)來做偽定時(shí)器
printf("%s\n",ctime(&t1)); //Wed Dec 19 16:29:14 2012
     
//init tm
my_tm->tm_year = 2012-1900;
my_tm->tm_mon = 12-1;
my_tm->tm_mday = 12;
my_tm->tm_hour = 12;
my_tm->tm_min = 12;
my_tm->tm_sec = 12;
      //設(shè)置時(shí)間
t1 = mktime(my_tm);
//獲取時(shí)間

my_tm = localtime(&t1);
sprintf(buf, "%04d-%02d-%02d  %02d:%02d:%02d",
my_tm->tm_year + 1900, my_tm->tm_mon + 1, my_tm->tm_mday, my_tm->tm_hour, my_tm->tm_min, my_tm->tm_sec);
printf("%s\n", buf);//2012-12-12  12:12:12

return 0;
}

上一篇:用c語言根據(jù)可變參數(shù)合成字符串的實(shí)現(xiàn)代碼

欄    目:C語言

下一篇:深入理解C/C++混合編程

本文標(biāo)題:解析Linux下的時(shí)間函數(shù):設(shè)置以及獲取時(shí)間的方法

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/4489.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有