time.h
来源:互联网 发布:介绍软件的ppt 编辑:程序博客网 时间:2024/05/18 00:33
1、时间获取
------------转为本地时间(localtime)
获取日历时间(time)------|
------------转为UTC时间(gmtime)
#include <stdio.h>#include <time.h>int main(void){struct tm *local;time_t it;//获取日历时间it = time(NULL);//转为本地时间local = localtime(&it);printf("the Local hour is:%d\n",local->tm_hour);//转为UTC时间local = gmtime(&it);printf("the UTC hour is:%d\n",local->tm_hour);return 0;}
运行结果
2、时间显示
时间获取后只是保存在一个结构体里面,并不能打印出来
为了方便将结构体里的数据转为一组字符串
=======UTC时间(gmtime)--------------转为字符串(asctime)
日历时间(time)=======|
||||
||
转为字符串(ctime)
#include <stdio.h>#include <time.h>int main(void){struct tm *local;time_t it;//获取日历时间it = time(NULL);//将日历时间转为UTC时间local = gmtime(&it);//将UTC时间转为字符串printf(asctime(local));//直接将日历时间转为字符串printf(ctime(&it));return 0;}
运行结果
0 0
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- “time.h”
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- time.h
- 15.7 Substring with Concatenation of All Words
- [Golong]学习笔记(一) 基础知识
- cygwin安装GNU make
- SOAP webserivce 和 RESTful webservice 对比及区别
- 背景图片铺满屏幕-------Day85
- time.h
- [Leetcode] Pow(x, n)
- NYOJ 题目135取石子(二)(博弈)
- jquery选定当前元素
- The type 类名 is already defined
- Codeforces Prison Transfer
- Oracle Database 12c 安装全过程
- 遗失的乔布斯访谈
- Android FakeID(Google Bug 13678484) 漏洞详解