gpt4 book ai didi

java - 无法转换 10 月 7 日星期二 :00:00 EEST 2014 to Date object

转载 作者:行者123 更新时间:2023-12-02 05:22:38 25 4
gpt4 key购买 nike

我正在尝试使用以下模式将此字符串“Tue Oct 07 03:00:00 EEST 2014”转换为日期对象:“E MMM dd HH:mm:ss Z yyyy”。我做错了什么?

最佳答案

您必须在此处使用区域设置。

例如:

String str = "Tue Oct 07 03:00:00 EEST 2014";
DateFormat df = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", Locale.US);
System.out.println(df.parse(str));

输出:

Tue Oct 07 05:30:00 IST 2014

来自Java doc .

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.

关于java - 无法转换 10 月 7 日星期二 :00:00 EEST 2014 to Date object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26377663/

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