函数: ctime
功 能: 把日期和时间转换为字符串
用 法: char *ctime(const time_t *time)
程序例:
#include<cstdio>
#include<ctime>
intmain(void) //返回值是int类型,用int来指示
{
time_tt //以秒计算
t=time(&t)
printf("Today'sdateandtime:%s\n",ctime(&t))
return0
}
注:若在linux下使用本函数,需要include <time.h>头文件。
没有#include
的写法,只有
#include
,time.h
是c语言里时间的库函数。
ctime在c语言里,只是一个把日期和时间转换为字符串的函数。具体函数原型为:
char
*ctime(
const
time_t
*timer
)
用法实例:
#include
#include
int
main(
void
)
{
time_t
ltime
time(
评论
0
0
加载更多
C Time LibraryThis header file contains definitions of functions to get and manipulate date and time information.FunctionsTime manipulation clockClock program (function)difftimeReturn difference between two times (function)mktimeConvert tm structure to time_t (function)timeGet current time (function)
Conversion:
asctimeConvert tm structure to string (function)ctimeConvert time_t value to string (function)gmtimeConvert time_t to tm as UTC time (function)localtimeConvert time_t to tm as local time (function)strftimeFormat time to string (function)
Macros CLOCKS_PER_SECClock ticks per second (macro)NULLNull pointer (macro)
types clock_tClock type (type )size_tUnsigned integral type (type)time_tTime type (type)struct tmTime structure (type) 请参阅:http://www.cplusplus.com/reference/clibrary/ctime/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)