文件I/O编程学习笔记三(linux 时间编程)

linux 时间编程


时间类型
coordinated universal time世界标准时间
calendar time日历时间


时间获取
#include <time.h>
time_t time(time_t *tloc)
从1970年1月1日0时到现在经历的秒数




时间转换
日历转化为格林威治标准时间
struct tm *gmtime(const time_t *timep)
日历时间转化为标准时间
struct tm *localtime(const time_t *timep)


tm结构体
struct tm{
int tm_sec;//秒值
int tm_min;//分钟
int tm_hour;
int tm_mday;//本月第几日
int tm_mon;
int tm_year;//+1900
int wday;//周几
int yday;//本年第几天
int tm_isdst;//日光节约时间
};


示例代码:
#include <stdio.h>
#include <time.h>
int main(void){
struct tm *local;
time_t t;
t=time(null);
local=localtime(&t);
printf("local hour is:%d\n",local->tm_hour);
local=gmtime(&t);
printf("utc hour is%d\n",local->tm_hour);
return 0;
}

时间显示
tm格式时间转化为字符串
char *asctime(const struct tm *timeptr)


将日历时间转化为本地时间后转字符串
char *ctime(const time_t *timep)


取得当前时间
int gettimeofday(struct timeval *tv,struct timezone *tz)


timeval结构体:
struct timeval{
int tv_sec;//秒
int tv_usec;//微秒
};




延时执行
让程序睡眠多少秒
unsigned int sleep(unsigned int seconds)


让程序睡眠多少微秒
void usleep(unsigned long usec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值