android - 如何在 android 中将 2021-07-06T19:27:46.811+0530 格式转换为 d MMM yyyy, hh:mm aaa 这种格式
问题描述
2021-07-06T19:27:46.811+0530 -> 当前值作为字符串
我想转换为 05/07/2021, 06:45 am 这种格式
提前致谢
解决方案
使用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
好的,这与显示您所需输出的示例的值不完全一样,但我认为这与此处的格式有关。调整这些值需要更多的努力,包括对所需行为的简要描述。
推荐阅读
- node.js - 如何从节点中的 express 访问 .env 变量?
- r - 如何对相似的字符串进行分组并为 R 中的每个组创建索引变量?
- python - Pandas 数据框列需要作为输入传递给另一个函数
- sql - 如何将函数从熊猫时间重写为sql?
- spring - 使用 spring-boot:run 时 Spring Boot 无法解析属性变量
- leaflet - 如何使用 Bootleaf / esri-leaflet 查询具有多边形层的点?
- python - 为什么我所有的分类准确度分数都一样?
- wget - wget只下载一个url到index.html,如何显示index.html的内容?
- python - ValueError:BitVects 的长度必须相同(rdkit)
- powershell - 无需使用 out-file 立即导入文件 使用 PowerShell 仅转换基本类型