Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4133245
  • 博文数量: 70
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1400
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-27 15:06
文章存档

2011年(2)

2010年(23)

2009年(21)

2008年(24)

我的朋友

分类: Java

2010-08-19 16:19:57

由于使用Date类型在数据库搜索大量数据时效率很低,公司采取使用Long型timecode进行搜索: Calendar calendar=Calendar.getInstance(); Long timecode=calendar.getTimeInMillis(); 但是由于不同机器不同系统的时区设置不同,所以同一时间产生的timecode的值也不同,导致搜索不到准确时间的数据的问题,所以采取如下方式进行解决: //将本地当前时间转换成UTC国际标准时间的毫秒形式 Date time=new Date(); Long timecode=time.UTC(time.getYear(), time.getMonth(), time.getDate(), time.getHours(), time.getMinutes(), time.getSeconds()); //将UTC国际标准时间的毫秒形式转换成本地的时间 Calendar calendar=Calendar.getInstance(); int offset=calendar.get(Calendar.ZONE_OFFSET); int dst=calendar.get(Calendar.DST_OFFSET); calendar.setTimeInMillis(timecode); calendar.add(Calendar.MILLISECOND, -(offset+dst)); Date resultDate=calendar.getTime(); 以上工作心得,如有不对请大家指正。
阅读(701) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~