网站建设需要基础吗,网站栏目页如何做,热门的网页设计工具有哪些,wordpress整合Linux高级编程——时间编程 宗旨#xff1a;技术的学习是有限的#xff0c;分享的精神是无限的。 1 时间类型
#xff08;1#xff09; 世界标准世界#xff08;格林威治时间#xff09;
#xff08;2#xff09; 日历时间#xff08;1970年1月1日0时#xff09;—…
Linux高级编程——时间编程 宗旨技术的学习是有限的分享的精神是无限的。 1 时间类型
1 世界标准世界格林威治时间
2 日历时间1970年1月1日0时——到此时经历的秒数 2 时间获取
#includetime.h
time_ttime(time_t *tloc)——获取日历时间
/*typedef longtime_t*/ 3 时间转化
struct tm*gmtime(const time_t *timep)
——将日历时间转化为格林威治标准时间并保存至TM结构中
struct tm*localtime(const time_t *timep)
——将日历时间转化为本地时间并保存至TM结构中 4 时间保存 struct tm
{int tm_sec;//秒值int tm_min;//分钟值int tm_hour;//小时值int tm_mday;//本月第几日int tm_mon;//本年第几月int tm_year;//tm_year1990哪一年int tm_wday;//本周第几日int tm_yday;//本年第几日int tm_isdst;//日光节约时间
};5 时间显示
char *asctime(conststruct tm* tm)
——将tm格式的时间转化为字符串
char*ctime(const time_t *timep)
——将日历时间转化为字符串 *Linux下显示系统时间实例 #include time.h
#include stdio.hint main(void)
{struct tm *ptr;time_t lt;/*获取日历时间*/lttime(NULL);/*转化为格林威治时间*/ptrgmtime(lt);/*以格林威治时间的字符串方式打印*/printf(asctime(ptr));/*以本地时间的字符串方式打印*/printf(ctime(lt));return 0;
}