android - 如何修复 org.threeten.bp.format.DateTimeParseException?

标签 android datetime utc datetime-parsing threetenbp

我正在将 UTC 时间转换为本地时间,但我遇到了错误:

org.threeten.bp.format.DateTimeParseException: Text 'Wed Oct 17 06:12:19 GMT+05:30 2018' could not be parsed at index 20

请说出任何其他选项或修复此解决方案..

这是我的代码,请检查:

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
    String formattedDate = LocalDateTime.parse(UTC_time, formatter)
            .atOffset(ZoneOffset.UTC)
            .atZoneSameInstant(ZoneId.systemDefault())
            .format(formatter);

最佳答案

使用这个

DateTimeFormatter formatter = 
       DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);

您可以使用这个 link找到你的模式

关于android - 如何修复 org.threeten.bp.format.DateTimeParseException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52851524/

相关文章:

android - 拒绝剪贴板访问 com.google.android.as(Android P 版本)

javascript - UTC 问题,Flot X 轴时间错误

python - Python 的 time.time() 是否返回 UTC 时间戳?

java - 在 Android 上存储和检索值

java - 如何在 TextView 中动态显示字符串列表中的项目

mysql - 如何在MySQL中获取 'Monday Date'?

java - Java中12小时制与24小时制的时间转换

wcf - 如何序列化 WCF 中的 UTC 日期时间以在末尾包含 "Z"?

android - 错误:无法解决:com.esri.arcgis.android:arcgis-android:10.2.6-2

Python pandas dataframe "Date"在 xlsx 和 csv 中索引不同的格式