【发布时间】:2021-07-06 17:09:33
【问题描述】:
就我而言,我有: “21 年 4 月 11 日星期日 09:09:13 +0000”
我的代码是:
Long result = null;
try {
DateTimeFormatter dateFormatterRssPubDate = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z");
result = dateFormatterRssPubDate.parseMillis(givenStringDate);
if(result!=null && result>=0)
return result;
} catch (Exception e) {
// logging
}
但它返回一个负数,例如: -61495771847000
我做错了吗? 如果是这样,在 java 中使用 Joda 将字符串日期转换为毫秒的最佳方法是什么?
【问题讨论】:
-
附带说明,RSS 使用 RFC-822 日期和时间格式,允许两位数年份。 RFC-1123 更新 RFC-822 以使用四位数年份。进一步说明,java.time,现代 Java 日期和时间 API 和 Joda-Time 的继任者,具有 RFC-1123 的内置格式化程序,DateTimeFormatter.RFC_1123_DATE_TIME。