Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / C语言:获取当前时间,并转为字符串

C语言:获取当前时间,并转为字符串,这个功能挺常用的,记录一下:#include <time.h>
#include <stdio.h>int main()
{
 time_t nowtime = time(NULL);
 tm *now = localtime(&nowtime);
 printf("now: %04d-%02d-%02d %02d:%02d:%02d unix time: %ld ",
  now->tm_year+1900, now->tm_mon+1, now->tm_mday,
  now->tm_hour, now->tm_min, now->tm_sec, (long)nowtime);
 return 0;
}推荐阅读:C++ 隐式类类型转化 Implicit Class-Type Conversions http://www.linuxidc.com/Linux/2013-01/78071.htmC语言变长数组之剖析 http://www.linuxidc.com/Linux/2013-07/86997.htmC语言需要注意的问题 http://www.linuxidc.com/Linux/2013-05/84301.htmC语言位域的使用及其注意点 http://www.linuxidc.com/Linux/2013-07/87027.htmC语言中简单的for循环和浮点型变量 http://www.linuxidc.com/Linux/2013-08/88514.htm 《C语言从入门到精通》.(王娣,韩旭 ).[PDF] + DVD视频光盘文件  http://www.linuxidc.com/Linux/2013-10/91775.htm