gpt4 book ai didi

java - 使用 SimpleDateFormat 解析日期

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

为什么下面会出错:

    DateFormat formatter1 = new SimpleDateFormat("E, MMM d");
formatter1.setTimeZone(TimeZone.getTimeZone("America/New_York"));

formatter1.parse("Tue, Nov 26");

我不明白为什么它不起作用。

最佳答案

您应该为格式化程序设置一个区域设置,其中月份以英语拼写,否则它将使用您的默认区域设置:

SimpleDateFormat(String pattern)

Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default locale.

即:

DateFormat formatter1 = new SimpleDateFormat("E, MMM d", Locale.US);

关于java - 使用 SimpleDateFormat 解析日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20253961/

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