从https://api.spacexdata.com/v3获取日期启动此日期的格式为:2006-03-25T10:30:00+12:00。我想将其转换为“DD,mm,YYYY”,但总是得到错误:“java.time.format.DateTimeParseException:Text'2006-03-25T10:30:00+12:00'could not be parsed,unparsed Text found at index 10”
我的代码:
val formatter = DateTimeFormatter.ofPattern("dd, mm, yyyy", Locale.US)
val myDate = LocalDate.parse(launchDate, formatter)
var launchDateConverted: String= myDate.toString()
我以字符串获取数据,然后将其转换为日期以进行格式化,然后将日期转换回字符串以显示在UI上。我用了不同的方法,但找不到正确的方法。我当前的区域设置是“Ru”。
val launchDate = "2006-03-25T10:30:00+12:00"
val inputFormatter = DateTimeFormatter.ISO_DATE_TIME
val myDate = LocalDate.parse(launchDate, inputFormatter)
val outputFormatter = DateTimeFormatter.ofPattern("dd, MM, yyyy", Locale.US)
println(outputFormatter.format(myDate))