C local time & UTC time
来源:互联网 发布:js option 选中事件 编辑:程序博客网 时间:2024/05/21 10:41
#include "stdafx.h"
#include <time.h>
//time,asctime,gmtime,localtime, mktime
//在先说明的C语言时间函数
//time_t time(time_t *timer);
//double difftime(time_t time1,time_t time2); //得到时间差
//struct tm *gmtime(const time_t *timer); //把日历时间转换成国际时间
//struct tm *localtime(const time_t *timer);
//char *asctime(const struct tm *timeptr); /将时间和日期以字符串格式表示
//char *ctime(const time_t *timer); //得到字符串表示的时间
//size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timeptr); //设定指定格式的时间
//time_t mktime(struct tm *timeptr); //设置时间
//clock_t clock(void) //得到处理器时间
int _tmain(int argc, _TCHAR* argv[])
{
time_t t=time(NULL);
printf("time_t: %ld\n", t);
tm *tLocal = localtime(&t);
printf("local time %d-%d-%d-%d-%d-%d tm_wday: %d, tm_yday: %d, tm_isdst: %d\n",
tLocal->tm_year+1900, tLocal->tm_mon+1, tLocal->tm_mday,
tLocal->tm_hour, tLocal->tm_min, tLocal->tm_sec,
tLocal->tm_wday, tLocal->tm_yday, tLocal->tm_isdst);
time_t ttLocal = mktime(tLocal);
printf("mktime(ttLocal): %ld\n", ttLocal);
tm *tUTC = gmtime(&t);
printf("UTC__ time %d-%d-%d-%d-%d-%d tm_wday: %d, tm_yday: %d, tm_isdst: %d\n",
tUTC->tm_year+1900, tUTC->tm_mon+1, tUTC->tm_mday,
tUTC->tm_hour, tUTC->tm_min, tUTC->tm_sec,
tUTC->tm_wday, tUTC->tm_yday, tUTC->tm_isdst);
time_t ttUTC = mktime(tUTC);
printf("mktime(tUTC)___: %ld\n", ttUTC);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
time_t: 1421303547
local time 2015-1-15-14-32-27 tm_wday: 4, tm_yday: 14, tm_isdst: 0
mktime(ttLocal): 1421303547
UTC__ time 2015-1-15-6-32-27 tm_wday: 4, tm_yday: 14, tm_isdst: 0
mktime(tUTC)___: 1421274747
注:1.tm *tLocal的值会被tm *tUTC清除,故取得tUTC值后,不能再使用tLocal值。
2.local time与utc time相差“时区”个小时,使用mktime转化成秒后,依然相差“时区”个小时
- C local time & UTC time
- UTC Time->Local Time
- Azure Website - UTC Time and Local Time
- how to convert UTC to local time
- CRM 2011 Online SSRS report UTC time to local time
- convert utc time to local time in excel
- UTC Time
- Time::local
- ASP.NET MVC - Display UTC time from server as local time on client side
- [android] UTC Time
- Difference between Unix Time and UTC time
- python time 字符串转UTC
- GPSTime To UTC Date Time
- Real-Time Local Reflections
- time.c
- Python: Convert UTC time-tuple to UTC timestamp
- List the UTC Time on a Computer
- Time: Epoch, TZ, GMT, UTC, LT
- 任性吗?【超值优惠 每天9元】
- xaml 思路
- SpringMVC4.1中使用FastJson
- Android Service 服务(三)—— bindService与remoteService
- jquery validator addMethod 方法的使用
- C local time & UTC time
- 正则严格验证身份证信息
- BJFU 1004——Sudoku
- 可记忆函数-递归优化
- eclipe常用快捷键
- 用Quick3.3简单开发微信打飞机02
- Linux常用命令总结
- Sqoop2学习(一)—Sqoop1.99.3介绍与安装
- Android 中 Handler 引起的内存泄露