localtime和gmtime函数使用
2016-04-17 12:38
453 查看
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { time_t timep; struct tm *tm_local,*tm_gmt; //get calendar time time(&timep); printf("%d\n",timep ); //convert to local time tm_local=localtime(&timep); //convert to gmt time tm_gmt=gmtime(&timep); printf("%s\n", asctime(tm_local)); printf("%s\n", asctime(tm_gmt)); printf("tmlocal point to 0X%x\n",tm_local); printf("tmgmt point to 0X%x\n",tm_gmt); return 0; }
大致介绍一下
先获取日历时间(从1970到现在的走的秒数)
然后将这个时间转换为本地时间和格林威治时间
然后打印两个时间
打印的时间是一样的
why?打印两个指针指向的内存地址,发现也是一样的,也就是说他俩用的一块内存。那么他是如何实现的呢?
“
Return Value
A pointer to a tm structure with the time information filled in.
This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the contents of this structure is overwritten.
“`
意思就是这块内存是静态分配的,两个函数共享使用。
那么他是在那里得到分配呢?
全局变量还是其它?
相关文章推荐
- 如何组织构建多文件 C 语言程序(二)
- 如何写好 C main 函数
- Lua和C语言的交互详解
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解
- C语言内存对齐实例详解
- C语言编程中统计输入的行数以及单词个数的方法
- C语言自动生成enum值和名字映射代码
- 使用C语言判断英文字符大小写的方法
- c语言实现的带通配符匹配算法
- C语言实现顺序表基本操作汇总
- C语言中计算正弦的相关函数总结
- 使用C语言详解霍夫曼树数据结构
- C语言实现选择排序、冒泡排序和快速排序的代码示例
- 探讨C语言的那些小秘密之断言
- C语言实现BMP转换JPG的方法
- 深入探讨C语言中局部变量与全局变量在内存中的存放位置