偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

linux下獲取系統(tǒng)時(shí)間的方法

運(yùn)維 系統(tǒng)運(yùn)維

可以用 localtime 函數(shù)分別獲取年月日時(shí)分秒的數(shù)值。

Linux下獲得系統(tǒng)時(shí)間的C語言的實(shí)現(xiàn)方法:

1. 可以用 localtime 函數(shù)分別獲取年月日時(shí)分秒的數(shù)值。

#include<time.h>     //C語言的頭文件

#include<stdio.h>     //C語言的I/O

void   main()

{

time_t   now;         //實(shí)例化time_t結(jié)構(gòu)

struct   tm     *timenow;         //實(shí)例化tm結(jié)構(gòu)指針

time(&now);

//time函數(shù)讀取現(xiàn)在的時(shí)間(國際標(biāo)準(zhǔn)時(shí)間非北京時(shí)間),然后傳值給now

timenow   =   localtime(&now);

//localtime函數(shù)把從time取得的時(shí)間now換算成你電腦中的時(shí)間(就是你設(shè)置的地區(qū))

printf("Local   time   is   %s\n",asctime(timenow));

//上句中asctime函數(shù)把時(shí)間轉(zhuǎn)換成字符,通過printf()函數(shù)輸出

}

注釋:time_t是一個(gè)在time.h中定義好的結(jié)構(gòu)體。而tm結(jié)構(gòu)體的原形如下:

struct   tm

{

int   tm_sec;//seconds   0-61

int   tm_min;//minutes   1-59

int   tm_hour;//hours   0-23

int   tm_mday;//day   of   the   month   1-31

int   tm_mon;//months   since   jan   0-11

int   tm_year;//years   from   1900

int   tm_wday;//days   since   Sunday,   0-6

int   tm_yday;//days   since   Jan   1,   0-365

int   tm_isdst;//Daylight   Saving   time   indicator

};

2. 對(duì)某些需要較高精準(zhǔn)度的需求,Linux提供了gettimeofday()。

#include   <stdio.h>

#include   <stdlib.h>

#include   <sys/time.h>

int  main(int argc,   char **argv)

{

struct   tim   start,stop,diff;

gettimeofday(&start,0);

//做你要做的事...

gettimeofday(&stop,0);

tim_subtract(&diff,&start,&stop);

printf("總計(jì)用時(shí):%d毫秒\n",diff.tv_usec);

}

int tim_subtract(struct tim *result, struct tim *x, struct tim *y)

{

int nsec;

if ( x->tv_sec > y->tv_sec )

return   -1;

if ((x->tv_sec==y->tv_sec) && (x->tv_usec>y->tv_usec))

return   -1;

result->tv_sec = ( y->tv_sec-x->tv_sec );

result->tv_usec = ( y->tv_usec-x->tv_usec );

if (result->tv_usec<0)

{

result->tv_sec--;

result->tv_usec+=1000000;

}

return   0;

}

【編輯推薦】

  1. 如何在Linux命令行模式下修改系統(tǒng)時(shí)間
  2. Debian下系統(tǒng)時(shí)間比正常時(shí)間快8小時(shí)的問題A>
  3. Linux內(nèi)核中的DeviceMapper機(jī)制
責(zé)任編輯:趙寧寧 來源: chinaitlab
相關(guān)推薦

2014-09-16 16:28:33

Linux

2020-11-04 11:25:33

Linux目錄命令

2011-08-22 15:39:38

Linux

2011-04-21 09:54:14

Linuxiptables

2011-08-16 14:18:09

UbuntuLinuxLinuxwindows

2009-09-07 09:56:02

Linux系統(tǒng)LVM擴(kuò)充Linux

2011-03-09 13:02:15

LinuxLAMP安裝

2011-01-07 17:08:22

linux系統(tǒng)時(shí)間

2009-07-01 09:13:10

Linux

2009-08-06 19:37:17

2009-07-27 10:27:34

Javascript

2009-06-25 08:53:03

Linux操作系統(tǒng)

2009-03-30 14:32:15

LinuxNetware服務(wù)器

2011-01-11 16:00:13

Linux軟件安裝

2011-03-03 15:21:11

2011-03-21 15:42:14

LinuxNagios

2010-05-28 11:05:56

Linux下dhcp測(cè)

2012-11-16 13:26:16

2009-06-29 09:21:41

Linux

2009-06-30 10:35:36

Linux
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)