当前位置: 编程技术>c/c++/嵌入式
c语言strftime时间格式化示例
来源: 互联网 发布时间:2014-10-24
本文导语: 函数原型: 代码如下:size_t strftime (char* ptr, size_t maxsize, const char* format,const struct tm* timeptr ); 代码示例: 代码如下:#include #include int main (){ time_t rawtime; struct tm * timeinfo; char buffer [128]; time (&rawtime); timeinfo =...
函数原型:
代码如下:
size_t strftime (char* ptr, size_t maxsize, const char* format,const struct tm* timeptr );
代码示例:
代码如下:
#include
#include
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [128];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,sizeof(buffer),"Now is %Y/%m/%d %H:%M:%S",timeinfo);
puts (buffer);
return 0;
}