gpt4 book ai didi

java - 无法解析 Twitter 中的日期

转载 作者:行者123 更新时间:2023-12-01 11:33:47 25 4
gpt4 key购买 nike

我通过 Twitter 的搜索 API 获取 Twitter 日期列表。

String dateString = ((JSONObject)ar.get(i)).get("created_at").toString();
// Ej: "Tue May 12 19:58:26 +0000 2015"
String TWITTER="EEE MMM dd HH:mm:ss ZZZZZ yyyy";
SimpleDateFormat sf = new SimpleDateFormat(TWITTER);
Date d = sf.parse(dateString);
LocalDate localDate = LocalDate.parse( new SimpleDateFormat("yyyy-MM-dd").format(d) );

谁能帮我看看我做错了什么?

我没有发现日期格式有任何错误。但是,我在 sf.parse(dateString); 上遇到了无法解析的日期异常线。

最佳答案

SimpleDateFormat 取决于区域设置,因此只需使用显式英语区域设置:

 String TWITTER="EEE MMM dd HH:mm:ss ZZZZZ yyyy";
SimpleDateFormat sf = new SimpleDateFormat(TWITTER,Locale.ENGLISH);

关于java - 无法解析 Twitter 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30202854/

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