Linux C高级编程——时间编程
生活随笔
收集整理的這篇文章主要介紹了
Linux C高级编程——时间编程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linux高級編程——時間編程
宗旨:技術的學習是有限的,分享的精神是無限的。
1 時間類型
(1) 世界標準世界(格林威治時間)
(2) 日歷時間(1970年1月1日0時)——到此時經歷的秒數
?
2 時間獲取
#include<time.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_year+1990=哪一年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.h>int main(void) {struct tm *ptr;time_t lt;/*獲取日歷時間*/lt=time(NULL);/*轉化為格林威治時間*/ptr=gmtime(lt);/*以格林威治時間的字符串方式打印*/printf(asctime(ptr));/*以本地時間的字符串方式打印*/printf(ctime(lt));return 0; }
總結
以上是生活随笔為你收集整理的Linux C高级编程——时间编程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue 创建图片坐标点_Vue Echa
- 下一篇: linux 其他常用命令