gpt4 book ai didi

java - "The constructor FastDateFormat(String, TimeZone, Locale) is not visible"是什么意思?

转载 作者:行者123 更新时间:2023-12-01 12:40:32 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com