[5]Linux时间编程

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);
//获取世界标准时间UTC
struct 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值