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()));
}
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
Helpe me please.
I have had many problems with date on android :(
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
.The value string
2018-07-22T14:00:00-03:00
can be parsed into anOffsetDateTime
without specifying aDateTimeFormatter
, since that is the default format of anOffsetDateTime
.If you then need to format that as
dd/MM/yyyy
, then use aDateTimeFormatter
.Don't know why your method takes 2 parameters.
Example: