C时间函数
2015-08-27 14:54
323 查看
C的几个时间函数,写一段小代码,把其全部囊括。
#include <stdio.h>
#include <time.h>
#include <assert.h>
int main()
{
time_t now = time(NULL);
printf("now utc is %d\n", now);
struct tm* gtmie = gmtime(&now);
struct tm* ctmie = localtime(&now);
time_t now2 = mktime(gtmie );
time_t now3 = mktime(ctmie );
assert (now==now2);
assert (now==now3);
printf("Time now is %s\n", asctime(gtmie));
printf("Time now is %s\n", asctime(ctmie));
printf("Time now is %s\n", ctime(&now));
char buf[124];
size_t len;
len = strftime(buf,124,"%Y-%m-%d %H:%M:%S %Z",gtmie);
printf("Time now is %s\n",buf);
}
#include <stdio.h>
#include <time.h>
#include <assert.h>
int main()
{
time_t now = time(NULL);
printf("now utc is %d\n", now);
struct tm* gtmie = gmtime(&now);
struct tm* ctmie = localtime(&now);
time_t now2 = mktime(gtmie );
time_t now3 = mktime(ctmie );
assert (now==now2);
assert (now==now3);
printf("Time now is %s\n", asctime(gtmie));
printf("Time now is %s\n", asctime(ctmie));
printf("Time now is %s\n", ctime(&now));
char buf[124];
size_t len;
len = strftime(buf,124,"%Y-%m-%d %H:%M:%S %Z",gtmie);
printf("Time now is %s\n",buf);
}
相关文章推荐
- Lua和C语言的交互详解
- 关于C语言中参数的传值问题
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言内存对齐实例详解
- 使用C语言判断英文字符大小写的方法
- c语言实现的带通配符匹配算法
- C语言实现顺序表基本操作汇总
- C语言中计算正弦的相关函数总结
- 使用C语言详解霍夫曼树数据结构
- 探讨C语言的那些小秘密之断言
- C语言实现BMP转换JPG的方法
- 深入探讨C语言中局部变量与全局变量在内存中的存放位置
- C语言查找数组里数字重复次数的方法
- C语言泛型编程实例教程
- C语言中使用lex统计文本文件字符数
- 在C语言中转换时间的基本方法介绍
- C语言进制转换代码分享
- 基于C语言fflush()函数的使用详解
- 对比分析C语言中的gcvt()和ecvt()以及fcvt()函数