java 获取est时间,将日期字符串(EST)转换为Java日期(UTC)

I need some advice on this java method. The intent of this method is to take a string that represents a date - this string was created from a date in the EST time zone - and convert it to a java Date object in the UTC time zone.

private Date buildValidationDate(String dateString) throws ParseException {

System.out.println("dateString " + dateString);

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyy hh:mm a");

dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

dateFormat.setLenient(true);

Date dt = dateFormat.parse(dateString);

System.out.println("dt " + dt);

return dt;

}

the problem I'm seeing is the value of dt seems to be off. For instance, if dateString is '10/16/2012 12:06 PM' - I'm expecting the value of dt (in UTC) to be something like 'Tuesday, October 16, 2012 4:06 PM'. Instead the value of dt is 'Tue Oct 16 07:06:00 CDT 2012'. This does not seem to be the correct UTC time.

I appreciate any advice, I'm sorry if this seems to be an easy question I have a lot of trouble with Java dates. I'm not sure if I'm coding something incorrectly or if there is something wrong with my methodology. Thanks

解决方案

Your date is getting converted right. Its just printing value in your default timezone format as java.util.Date is timezone independent. If you want timezone specific handling, please use java.util.Calendar.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值