2021-07-06T19:27:46.811+0530 -> 当前值作为字符串
我想转换为 05/07/2021, 06:45 am 这种格式
提前致谢
Use java.time
:
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
fun main() {
val input = "2021-07-06T19:27:46.811+0530"
// define a DateTimeFormatter for parsing your input
val parser = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSx")
// and another one for formatting your output
val formatter = DateTimeFormatter.ofPattern("dd/MM/uuuu, hh:mm a")
// then parse the input to an OffsetDateTime using the parser
val converted: String = OffsetDateTime.parse(input, parser)
// and output the same time differently
.format(formatter)
// output the result
println(converted)
}
这段代码的输出是
06/07/2021, 07:27 PM
好吧,这并不完全是显示您所需输出的示例中的值,但我认为这都是关于格式化的。调整这些值需要更多的努力,包括对所需行为的简要描述。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)