C/C++中关于时间的函数 ctime()
2012-04-23 14:36
399 查看
函数:ctime (const time_t * timer);
作用,将time_t型的时间转换为易读的string,转换后的string长度为25. 其格式为:
Www Mmm dd hh:mm:ss yyyy
但是有时只想提取其中的时间(hh:mm:ss),于是我写了下面一个小程序,用来提取其中的时间:
作用,将time_t型的时间转换为易读的string,转换后的string长度为25. 其格式为:
Www Mmm dd hh:mm:ss yyyy
但是有时只想提取其中的时间(hh:mm:ss),于是我写了下面一个小程序,用来提取其中的时间:
#include <stdio.h> #include <time.h> #include <string.h> #define N 50 int main() { time_t test; test = time(NULL);//抓取现在的时间 ——目前距离1970-01-01-00:00:00所经历的秒数 printf("now is %s\n",ctime(&test));//将上面的秒数转换为人们易读的时间表达方式 ,并在末尾换行 printf("length of ctime = %d\n",strlen(ctime(&test)));//ctime()所产生的字符串的长度 char c ;//提取其中的时间 strcpy(c,ctime(&test));//先将其赋值给c for(int i=11; i<=18;i++)//取第12位到第19位,注意,第一位为 i = 0; printf("%c",c[i]);//打印时间 printf("\n"); return 0; }
相关文章推荐
- C/C++中关于时间的函数 time()
- C/C++中关于时间的函数 time()
- 关于标准c++ 利用clock()函数计算时间为负值原因及解决
- c\c++ 时间相关函数 include<time.h>
- C/C++中关于时间的函数 clock()
- 关于php页面最大执行时间问题(set_time_limit函数在windows下不起作用的解决)
- 关于php页面最大执行时间问题(set_time_limit函数在windows下不起作用的解决)
- 关于ThinkPHP5.0*的软删除delete_time的引用和部分时间函数where(),whereTime()连贯操作的问题
- Linux时间函数C++之gettimeofday()函数之使用方法
- C++中time时间函数的一个简单实例
- 关于php页面最大执行时间问题(set_time_limit函数在windows下不起作用的解决)
- C/C++中关于时间的函数 localtime()
- 关于使用time.h和clock()函数获得程序运行时间
- c++——时间函数Time
- <C/C++>日期和时间的使用(time相关函数大全)
- [c++]关于时间函数的总结
- C++中的时间函数
- 关于C++中函数返回引用的讨论
- C语言gettimeofday()函数:获取当前时间
- 关于C++对函数传参与函数返回值进行引用传递的详解