[5]Linux时间编程

来源:互联网 发布:java的可变参数 编辑:程序博客网 时间:2024/06/05 07:20

1.1 获取日历时间

#include <time.h>time_t time(time_t *calptr);//返回距计算机元年的秒数#define time_t long

1.2 获取格林威治时间

#include <time.h>    struct tm *gmtime(const time_t *calptr);//获取世界标准时间UTCstruct tm {     int  tm_sec;     /* seconds after the minute: [0 - 60] */     int  tm_min;     /* minutes after the hour: [0 - 59] */     int  tm_hour;    /* hours after midnight: [0 - 23] */     int  tm_mday;    /* day of the month: [1 - 31] */     int  tm_mon;     /* months since January: [0 - 11] */     int  tm_year;    /* years since 1900 */     int  tm_wday;    /* days since Sunday: [0 - 6] */     int  tm_yday;    /* days since January 1: [0 - 365] */     int  tm_isdst;   /* daylight saving time flag: <0, 0, >0 */  // 以下两个字段在有些版本中是存在的,使用时需要查看对应的头文件确认  long int tm_gmtoff; /* Seconds east of UTC. */  const char *tm_zone; /* Timezone abbreviation. */   };  

1.3 获取本地时间

#include <time.h>struct tm *localtime(const time_t *calptr);//获取本地时间

1.4 以字符串方式显示时间

#include <time.h>char *asctime(const struct tm *tmptr);//获取时间对应的字符串表示形式

1.5 获取高精度时间

#include<sys/time.h>int gettimeofday(struct timeval*tv,struct timezone *tz);//获取高精度的时间struct  timeval{       long  tv_sec;/*秒*/       long  tv_usec;/*微妙*/};

来自国嵌【2014】应用程序开发

0 0
原创粉丝点击