Unix/Linux编程-时间和日期
2017-10-24 16:17
423 查看
时间和日期
有Unix内核提供的基本时间服务是计算自协调世界时(UTC)公元1970年1月1日00:00:00这一特定时间以来经过的秒数。以数据类型time_t表示。#include <time.h> time_t time(time_t *calptr); 返回值:成功返回时间值,出错返回-1 |
localtime和gmtime将日历时间转换成分解的时间,并将这些存放在一个结构体中:
struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ }; |
#include <time.h> struct tm * gmtime(const time_t *calptr); struct tm *locatime(const time_t *calptr); 返回值:指向分解的tm结构的指针;出错返回NULL |
函数mktime以本地时间作为参数,将其变成time_t值。
#include <time.h> time_t mktime(struct tm *tmptr); 返回值:成功返回日历时间,出错返回-1 |
相关文章推荐
- Unix/Linux环境C编程入门教程(28) 日期时间那些事儿
- Unix/Linux环境C编程入门教程(28) 日期时间那些事儿
- Unix/Linux编程日期时间汇编
- unix环境C编程之日期时间转换
- Linux 时间和日期相关编程
- Unix/Linux环境C编程入门教程(22) C/C++如何获取程序的运行时间
- unix环境C编程之日期时间转换
- Unix环境编程-时间和日期
- Unix/Linux环境C编程新手教程(22) C/C++怎样获取程序的执行时间
- UNIX环境高级编程——时间和日期
- 按照如下格式的命令设置Linux Solaris Unix系统日期和时间。
- UNIX环境高级编程——时间和日期
- Mysql日期时间类型(DATE,DATETIME,TIMESTAMP)和函数及与linux系统时间之间的转换(UNIX_TIMESTAMP、FROM_UNIXTIME)
- UNIX环境高级编程——时间和日期
- Unix/Linux环境C编程入门教程(22) C/C++如何获取程序的运行时间
- Linux或Unix下怎样修改系统时间
- linux date 格式化时间和日期
- 09.12.13 linux/unix编程学习途径 关于个人技术发展的一些考量
- Qt编程19:Qt时间日期的处理(QTime、QDateTime的使用比较简单)
- Linux文件与时间编程2