Time/Timer in Linux vs. Windows

数据类型

time_t: Calendar time

#include <time.h>

time_t time(time_t *t);

[obsoleted by gettimeofday]获取自从1970.1.1 00:00:00到现在为止的时间,以秒为单位。

#include <sys/timeb.h>

int ftime(struct timeb *tp);

[Obsoleted]

#include <time.h>

int clock_getres(clockid_t clk_id, struct timespec *res);
int clock_gettime(clockid_t clk_id, struct timespec *tp);
int clock_settime(clockid_t clk_id, const struct timespec *tp);

clock_getres() 获取由clk_id制定的时钟精度。clk_id是system-wide的,因此他对所有进程都是visible的,通常会有下面的时钟:

CLOCK_REALTIME
System-wide realtime clock. Setting this clock requires appropriate privileges.
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point.
CLOCK_PROCESS_CPUTIME_ID
High-resolution per-process timer from the CPU.
CLOCK_THREAD_CPUTIME_ID
Thread-specific CPU-time clock.

#include <sys/time.h>

int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);

获取时间和timezone。可以精确到微秒。

#include <time.h>

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);
struct tm *gmtime_r(const time_t *timep, struct tm *result); struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result); time_t mktime(struct tm *tm);
 
Windows
FILETIME: 64位的数值,代表从1601,1,1以来的100-naosecond的数量。
SYSTEMTIME:使用多个独立的member代表日期和时间,精确到millisecond。

DYNAMIC_TIME_ZONE_INFORMATION
TIME_ZONE_INFORMATION

http://msdn.microsoft.com/en-us/library/ms725479(v=VS.85).aspx
 
 
 
 
 
 
 
 
 
 
 
 
原文地址:https://www.cnblogs.com/whyandinside/p/2002394.html