我试图将当前日期转换为“UTC”时区格式。
以下是操作:
以字符串格式为Mon Apr 11 09:57:12 +0000 2016 解析后的日期为Mon Apr 11 15:27:12 IST 2016
当我尝试将日期(Parse)从字符串转换为日期格式时,我得到的日期是当前日期时间,并且也是IST格式。
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
DateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String dat = sdf.format(cal.getTime());
System.out.println("In string format" + dat);
System.out.println(("Date After parses " + (Date) sdf.parse(dat)));
以下是操作:
以字符串格式为Mon Apr 11 09:57:12 +0000 2016 解析后的日期为Mon Apr 11 15:27:12 IST 2016
当我尝试将日期(Parse)从字符串转换为日期格式时,我得到的日期是当前日期时间,并且也是IST格式。
Date
对象本身没有与之关联的时区... 如果你想以特定的时区打印它,你需要像你所做的那样使用DateFormat.format()
... - CodebenderDate
对象而更改默认时区,那么这样做是错误的...你想要解决的问题是什么?为什么不使用DateFormat输出Date对象? - Codebender