C/C++中关于时间的函数 localtime()
2012-04-23 22:22
441 查看
函数:struct tm * localtime ( const time_t * timer );
#include <stdio.h> #include <time.h> int main() { time_t test; test = time(NULL);//抓取现在的时间 ——目前距离1970-01-01-00:00:00所经历的秒数 printf("%s\n",ctime(&test));//将上面的秒数转换为人们易读的时间表达方式 ,并在末尾换行 printf("local hour:%d\n",localtime(&test)->tm_hour); //localtime的返回值是一个指向tm结构的指针,tm见程序最后注释部分 //使用asctime()可以讲 tm 结构转换为人们易读的string格式 (同ctime()) struct tm * ptime; ptime = localtime(&test); printf("%s\n",asctime(ptime)); return 0; } /* The structure contains nine members of type int, which are (in any order): int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; tm_sec seconds after the minute 0-61* tm_min minutes after the hour 0-59 tm_hour hours since midnight 0-23 tm_mday day of the month 1-31 tm_mon months since January 0-11 tm_year years since 1900 tm_wday days since Sunday 0-6 tm_yday days since January 1 0-365 tm_isdst Daylight Saving Time flag */
相关文章推荐
- C/C++中关于时间的函数 time()
- 关于localtime 函数输出与上海时间不同
- C++ 时间函数gmtime、gmtime_r、localtime、localtime_r
- C/C++中关于时间的函数 ctime()
- [c++]关于时间函数的总结
- 关于标准c++ 利用clock()函数计算时间为负值原因及解决
- c/c++ 时间函数 localtime 坑
- 关于时间函数localtime()返回值的注意问题
- C/C++中关于时间的函数 clock()
- C/C++中关于时间的函数 time()
- linux c/c++ 编程之-----时间函数
- 关于C++的右值、const引用、右值引用、const成员函数及相关扩展
- 在C++里面关于strcpy()函数和strcpy_s()函数的问题
- 使用递推法求解Fibonacii数列并用C++函数记录运行时间
- Sql关于时间的一些常用函数
- 关于C++ map容器的使用和pair类型及函数
- C++ 关于const和函数
- c++关于const和函数
- C/C++时间函数使用方法
- 关于c++和C的getXXX系列函数