UTC时间转本地日期时间的实现
来源:互联网 发布:国密算法性能测试 编辑:程序博客网 时间:2024/05/19 14:38
根据时区,把UTC时间转换为本地时间。很简单,看代码吧
struct DATETIME{uint16 year;uint8 month;uint8 day;uint8 hours;uint8 minute;uint8 seconds;uint8 microsecond;DATETIME(){clear();}void clear(){year = 1970;month = 1;day = 1;hours = 0;minute = 0;seconds = 0;microsecond = 0;}/*!< 根据指定时区转为当前日期和时间。Ex: 转为北京时间 -> transToLocal(8)*/void transToLocal(int8 timezone){uint8 nLastDayOfMonth = 0;//每个月的最后一天if(timezone == 0){return;}hours += timezone;if (hours > 23){hours -= 24;day++;switch (month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:nLastDayOfMonth = 31;break;case 2:if (((0 == year % 4) && (0 != year % 100)) || (0 == year % 400)){/*!< 闰年的2月有29天*/nLastDayOfMonth = 29;}else{nLastDayOfMonth = 28;}break;case 4:case 6:case 9:case 11:nLastDayOfMonth = 30;break;default:return;}if (day > nLastDayOfMonth){day = 1;if(month == 12){month = 1;year++;}else{month++;}}}else if(hours < 0){hours += 24;if(day == 1){switch (month){case 1:/*!< 处理1月1日*/day = 31;month = 12;year--;return;case 3:case 5:case 7:case 8:case 10:case 12:nLastDayOfMonth = 31;break;case 2:if (((0 == year % 4) && (0 != year % 100)) || (0 == year % 400)){nLastDayOfMonth = 29;}else{nLastDayOfMonth = 28;}break;case 4:case 6:case 9:case 11:nLastDayOfMonth = 30;break;default:return;}month--;day = nLastDayOfMonth;}else{day--;}}}};
0 0
- UTC时间转本地日期时间的实现
- 关于UTC时间的转本地时间
- 本地时间转UTC时间
- UTC时间&本地时间
- UTC转换本地时间
- UTC转换本地时间
- UTC转换本地时间
- 获取本地时间,UTC时间
- UTC时间转为本地时间
- utc 和本地时间的转化
- GPS,UTC和本地时间的显示器
- 查看指定日期的UTC时间
- utc date 转 本地时间(java)
- 本地时间和GMT(UTC)时间的转换
- 本地时间和GMT(UTC)时间的转换(C#)
- 本地时间和GMT(UTC)时间的转换
- 把给定的本地时间批量转成UTC时间
- 本地时间与UTC(世界协调时间)的转换
- cocos2d-x_lua 开发 开始(一) 开发环境搭建
- [高斯消元] poj 1753 Flip Game
- 极大似然估计
- CPU cache 与内存对齐
- Apache 漏洞之后缀名解析漏洞
- UTC时间转本地日期时间的实现
- Maven Project to Dynamic Web Project
- NetBeans工具学习之道:NetBeans IDE Java 快速入门教程
- light oj 1032 - Fast Bit Calculations(数位dp 记忆化搜索解法)
- 100课堂:美文欣赏:赐予我生命的女人(双语)
- C# 字符串与十六进制转换
- php一个利用cookie限时发帖的小程序
- Codeforces Round #258 (Div. 2)
- Android开发日记(1) android开发环境搭建(ubuntu)