【发布时间】:2014-02-26 20:17:31
【问题描述】:
我尝试将 Tics 中的日期转换为 UTC 日期时间格式 - 'YYYY-MM-DDThh:mm:ss'
public static DateFormat getFormat() {
String systemLocale = System.getProperty("user.language"); //$NON-NLS-1$
Locale locale = new Locale(systemLocale);
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
return dateFormat;
}
public static Object getFormatedValue(Object value) {
String updated = (strValue).replaceAll(pattern, "$1"); //$NON-NLS-1$
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.parseLong(updated));
return getFormat().format(new Date(calendar.getTimeInMillis()));
}
public static Object getOdataValue(Object value) throws ParseException {
DateFormat dateFormat = getFormat();
Date parse = dateFormat.parse(value.toString());
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(parse.getTime());
return "\"/Date(" + calendar.getTimeInMillis() + ")/\""; //$NON-NLS-1$ //$NON-NLS-2$
}
例如,我得到 UTC 的 dtae 时间结果的问题 -
1393358368000 = 2014 年 2 月 25 日星期二 19:59:28 GMT
您的时区:2014 年 2 月 25 日晚上 9:59:28 GMT+2
此代码的结果是 2/25/2014 21:59:28 PM
如何在没有时区的情况下获得结果?在这种情况下,我希望结果是 2014 年 2 月 25 日 19:59:28 GMT 我可以在有和没有 UTC 的情况下打勾并得到不同的结果吗?
【问题讨论】:
-
“我可以打勾并在有和没有 UTC 的情况下得到不同的结果吗?”是什么意思? - 不太清楚你在问什么。
-
查看我的示例 1393358368000 = 2014 年 2 月 25 日星期二 19:59:28 GMT 在我的代码中,结果是 2014 年 2 月 25 日星期二 21:59:28 GMT。我怎样才能得到结果将没有 GMT+2 含义,2014 年 2 月 25 日星期二 19:59:28
-
您的代码的结果根本不是这样 - 它是
"/Date(1393358368000)/"形式的字符串 - 您在哪里看到 GMT+2 的值?请注意,您根本不需要创建Calendar- 只需调用parse.getTime()即可获得相同的毫秒值。 -
getOdataValue = /Date(1393358368000)/` 但 getFormatedValue 将是 2014 年 2 月 25 日星期二 21:59:28
-
啊,对。不清楚你的意思。我现在将添加一个答案。
标签: java