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