C語言time頭文件(time.h)中ctime函數的用法及代碼示例。
用法:
char* ctime (const time_t * timer);
將time_t值轉換為字符串
返回的字符串具有以下格式:
Www Mmm dd hh:mm:ss yyyy |
在哪裏Www是工作日Mmm一個月(以字母為單位),dd一個月中的某天,hh:mm:ss時間,和yyyy那一年。
字符串後跟一個new-line字符(
'\n'
),並以null-character終止。此函數等效於:
/* ctime example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, time, ctime */
int main ()
{
time_t rawtime;
time (&rawtime);
printf ("The current local time is: %s", ctime (&rawtime));
return 0;
}
有關自定義日期格式的替代方法,請參見strftime。
參數
返回值
C-string包含人類可讀格式的日期和時間信息。返回的值指向一個內部數組,該數組的有效性或值可通過隨後的任何調用來更改asctime或者ctime。
示例
/* ctime example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, time, ctime */
int main ()
{
time_t rawtime;
time (&rawtime);
printf ("The current local time is: %s", ctime (&rawtime));
return 0;
}
輸出:
The current local time is: Wed Feb 13 16:06:10 2013 |
相關用法
- C語言 clock用法及代碼示例
- C語言 difftime用法及代碼示例
- C語言 mktime用法及代碼示例
- C語言 time用法及代碼示例
- C語言 asctime用法及代碼示例
- C語言 gmtime用法及代碼示例
- C語言 localtime用法及代碼示例
- C語言 strftime用法及代碼示例
注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C ctime function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。