- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SimpleDateFormat 让我可以这样做:
SimpleDateFormat mySimpleDateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
但 FastDateFormat 不会:
import org.apache.commons.lang3.time.FastDateFormat;
//...
FastDateFormat myFastDateFormatter = new FastDateFormat(str, tz, loc);
现在它提示:
"The constructor FastDateFormat(String, TimeZone, Locale) is not visible"
错误消息不会引导我到任何地方...我做错了什么?
最佳答案
与 Java 的 SimpleDateFormat
不同,您不能简单地声明 Apache 的 FastDateFormat
类的实例。
相反,FastDateFormat
通过 Factory Method Pattern 静态提供该类的实例。 - 您必须调用类的静态方法getInstance
,如下所示:
String dateFormatPattern = "yyyy-mm-dd'T'HH:mm:ss.SSSZ";
FastDateFormat myFastDateFormatter = FastDateFormat.getInstance(dateFormatPattern);
现在您已经加载了一个 myFastDateFormatter,并配置了该日期格式模式。
您可以使用它将字符串解析为真正的日期,假设这些字符串符合您的 dateFormatPattern:
String dateString = "2014-04-03T14:02:57.182+0200";
Date myDate = myFastDateFormatter.parse(dateString);
关于java - "The constructor FastDateFormat(String, TimeZone, Locale) is not visible"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145404/
我一直在绞尽脑汁试图理解为什么 FastDateFormat 解析器返回的时间非常不正确。我尝试转换的字符串时间戳采用 GMT/UTC 格式,我正尝试将其插入 DB2 中的时间戳列。 代码如下: St
我想通过 FastDateFormat 将 String 解析为 Date 对象。 simpleDateStr 是 "04/13/2017" 这是我的代码: private static final
非常了解 SimpleDateFormat 的性能和线程问题,我决定使用 FastDateFormat,直到我意识到 FastDateFormat 仅用于格式化,不解析! 是否有 FastDateFo
我是 Spring 开发的新手,所以我尝试将 Jersey RESTful api 依赖项添加到我的一个 Maven 项目中。不幸的是,我不得不添加一些远程存储库,这似乎搞砸了我的启动配置。现在,当我
源 FastDateFormat.getInstance("HHmmssS").format(Calendar.getInstance()); 返回格式为“HHmmssSSS”的字符串,例如15271
这是一个简单的单元测试来说明我遇到的问题。 package mytest; import java.text.ParseException; import java.text.SimpleDateFo
SimpleDateFormat 让我可以这样做: SimpleDateFormat mySimpleDateFormatter = new SimpleDateFormat("dd-MMM-yyyy
我使用了 SimpleDataFormat,它似乎不是一个非常线程安全的东西。然后我发现 FastDateFormat是这个问题的替代方案。但我想弄清楚如何使用它来解析带有日期和时间的字符串。 这里解
我有两个用于日期解析的格式字符串:“yyyy-MM-dd”和“dd-MM-yyyy”,我希望 FastDateFormat 类能够区分这两者,以便通过 ParseException另一个会起作用。然而
我是一名优秀的程序员,十分优秀!