org.threeten.bp.format.DateTimeParseException:无法在索引19处解析文本'2018-07-22T14:00:00-03:00' [英] org.threeten.bp.format.DateTimeParseException: Text '2018-07-22T14:00:00-03:00' could not be parsed at index 19

查看:546
本文介绍了org.threeten.bp.format.DateTimeParseException:无法在索引19处解析文本'2018-07-22T14:00:00-03:00'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public static String formatter(String dateInPattern, String dateOutPattern) {
    OffsetDateTime dateInPatternFormat = OffsetDateTime.parse(dateInPattern, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"));
    Date dateInValue = DateTimeUtils.toDate(Instant.parse(dateInPatternFormat.toString()));
    OffsetDateTime dateOutPatternFormat = OffsetDateTime.parse(dateOutPattern);

    return dateOutPatternFormat.format(DateTimeFormatter.ofPattern(dateInValue.toString()));

}

我需要以这种方式输入日期yyyy-MM-dd'T'HH:mm:ss'Z'等于(2018-07-22T14:00:00-03:00). 我需要以dd/MM/yyyy

I need to enter a date in this pattern yyyy-MM-dd'T'HH:mm:ss'Z' this is equals (2018-07-22T14:00:00-03:00). And I need an output in this pattern dd/MM/yyyy

请帮助我.

我在android上的日期有很多问题:(

I have had many problems with date on android :(

推荐答案

您的代码很混乱,名称很奇怪,您似乎混淆了 pattern 字符串,例如yyyy-MM-dd,带有 value 字符串,例如2018-07-22.

Your code is very confusing, with weird names and you seem to be mixing up pattern strings, e.g. yyyy-MM-dd, with value strings, e.g. 2018-07-22.

可以将值字符串2018-07-22T14:00:00-03:00解析为OffsetDateTime,而无需指定DateTimeFormatter,因为这是OffsetDateTime的默认格式.

The value string 2018-07-22T14:00:00-03:00 can be parsed into an OffsetDateTime without specifying a DateTimeFormatter, since that is the default format of an OffsetDateTime.

如果您随后需要将其格式格式化为dd/MM/yyyy,请使用DateTimeFormatter.

If you then need to format that as dd/MM/yyyy, then use a DateTimeFormatter.

不知道为什么您的方法需要2个参数.

Don't know why your method takes 2 parameters.

示例:

String input = "2018-07-22T14:00:00-03:00";
OffsetDateTime offsetDateTime = OffsetDateTime.parse(input);
String output = offsetDateTime.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
System.out.println(output); // prints: 22/07/2018

这篇关于org.threeten.bp.format.DateTimeParseException:无法在索引19处解析文本'2018-07-22T14:00:00-03:00'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆