linux系統時間程式設計(8) UTC秒數轉本地字串時間
<time.h> | ||
---|---|---|
char* ctime ( const time_t* timer ); | (1) | |
char* ctime_r( const time_t* timer, char* buf ); | (2) | (since C23) |
errno_t ctime_s( char buf, rsize_t bufsz, const time_t timer ); | (3) | (since C11) |
該函式執行了兩步操作,相當於:
asctime(localtime(timer)) or asctime(localtime_r(timer, &(struct tm){0}))
返回的字串格式:
Www Mmm dd hh:mm:ss yyyy\n
- Www - the day of the week (one of Mon, Tue, Wed, Thu, Fri, Sat, Sun).
- Mmm - the month (one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
- dd - the day of the month
- hh - hours
- mm - minutes
- ss - seconds
- yyyy - years
同樣執行緒不安全。
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t result = time(NULL);
printf("%s", ctime(&result));
#ifdef __STDC_LIB_EXT1__
char str[26];
ctime_s(str,sizeof str,&result);
printf("%s", str);
#endif
}
Possible output:
Tue May 26 21:51:03 2015
Tue May 26 21:51:03 2015
相關文章
- 本地時間與UTC(世界協調時間)的轉換
- linux系統時間程式設計(6) 日曆時間tm轉字串strftime函式Linux程式設計字串函式
- utc時間轉換成標準時間
- UTC格式時間轉換為當地時間程式碼
- Linux程式設計(獲取系統時間)Linux程式設計
- JavaScript 轉換成UTC時間JavaScript
- Linux時間設定系統時間、硬體時間和時間服務Linux
- linux系統時間程式設計(9) 計算程式片段執行時間clock函式Linux程式設計函式
- JavaScript 時間轉換為UTC格式JavaScript
- 安卓核心時間使用的是UTC時間安卓
- 時間相差秒數_Golang 時間操作大全Golang
- 如何將UTC時間轉換為Unix時間戳(How to convert UTC time to unix timestamp)時間戳
- Arch Linux中禁用UTC解決雙系統時間問題Linux
- linux系統時間設定Linux
- Linux設定系統時間Linux
- linux下的系統時間、硬體時間設定Linux
- 轉:24時區,GMT,UTC,DST,CST時間詳解
- Linux 系統時間和硬體時間Linux
- 時間日期字串轉換為時間物件字串物件
- php 將秒數轉換為時間(年、天、小時、分、秒)PHP
- mysql時間操作(時間差和時間戳和時間字串的互轉)MySql時間戳字串
- 修改系統時間(轉)
- 如何將時間字串轉換為時間物件字串物件
- Perl中本地時間和UNIX時間戳間相互轉換時間戳
- 時間戳與時間字串的多時區轉換時間戳字串
- python中的時間轉換,秒級時間戳轉string,string轉時間Python時間戳
- iOS倒數計時設計思路和一個系統時間的坑iOS
- 如何設計一個秒殺系統-許令波-極客時間
- Linux系統時間與RTC設定Linux
- ORACLE計算2個時間段相差時間小時、分、秒Oracle
- 修改linux系統時間Linux
- linux同步系統時間Linux
- linux修改系統時間Linux
- linux 修改系統時間Linux
- 線上直播系統原始碼,預設倒數計時,自定義輸入時間倒數計時原始碼
- Python秒轉換成時間(時分秒)Python
- PAT乙級1026程式執行時間(秒數轉換為時間)(值得學習)
- oracle轉換JAVA生成的時間數字串OracleJava字串