<分区>
我正在尝试在 java 中读取当前系统日期和时间格式,但在分析之后我找不到任何相关方法,所以任何人都可以帮助我。这就是我想从 java 中读取的内容。
<分区>
我正在尝试在 java 中读取当前系统日期和时间格式,但在分析之后我找不到任何相关方法,所以任何人都可以帮助我。这就是我想从 java 中读取的内容。
最佳答案
要获取当前系统区域设置的 DateTimeFormatter
,您可以使用 DateTimeFormatter.ofLocalizedDateTime()
FormatStyle
参数控制您是需要长表示还是短表示(太平洋标准时间 1952 年 4 月 12 日星期二下午 3:30:42 与太平洋标准时间 12.13.52 下午 3:30)。
一些示例以及我在本地系统上得到的结果:
//Tuesday, 2 April 2019 at 5:49:39 pm Australian Eastern Daylight Time
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).format(ZonedDateTime.now())
//2 April 2019 at 5:50:20 pm AEDT
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).format(ZonedDateTime.now())
//2/4/19, 5:50 pm
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).format(ZonedDateTime.now())
关于java - 如何在java中获取系统日期和时间格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55468270/