MySQL 保存bc网站搭建时间信息的建议

解决方案参考如下,bc网站搭建【企鹅21717-93408】即在SimpleDateFormat对象基础上需要明确当前需要使用的时区是什么。

SimpleDateFormat.setTimeZone(TimeZone);

// Java:
long timeMs = System.currentTimeMillis();
System.out.println("long = " + timeMs);

// current time zone
SimpleDateFormat default = new SimpleDateFormat("yyyy-MM-dd HH:mm");
System.out.println(default.format(timeMs));

// +8:00 time zone
SimpleDateFormat chinaFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
chinaFormat.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
System.out.println("GMT+8:00 = " + chinaFormat.format(timeMs));

// +5:30 time zone
SimpleDateFormat indiaFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
indiaFormat.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
System.out.println("GMT+5:30 = " + indiaFormat.format(timeMs));
使用如上方法其实就可以解决时区问题,由于我当时获取统计数据是通过小时表获取的且小时表是一小时一条记录。而印度时区为GMT+5:30,在当前表结构的基础上会存在半小时数据偏差的问题,因此为了解决该问题我们修改小时表的统计粒度为半小时。

猜你喜欢

转载自blog.51cto.com/14282627/2375700