小编Gro*_*oot的帖子

在 java 8 中解析时间字符串 - ClockHourOfAmPm 的值无效

我正在尝试在我的属性文件中转换具有给定时间的时区。

 package test1;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class TimeZoneConversion {

private static final String DATE_FORMAT = "yyyy-MM-dd-hh-mm-ss";

public static void main(String[] args) {

    String ds = "2019-03-18 13-14-48";
    LocalDateTime ldt = LocalDateTime.parse(ds, DateTimeFormatter.ofPattern(DATE_FORMAT));
    System.out.println("ldt : "+ldt);

    ZoneId singaporeZoneId = ZoneId.of("Asia/Singapore");
    System.out.println("TimeZone : " + singaporeZoneId);

    //LocalDateTime + ZoneId = ZonedDateTime
    ZonedDateTime asiaZonedDateTime = ldt.atZone(singaporeZoneId);
    System.out.println("Date (Singapore) : " + asiaZonedDateTime);

    ZoneId newYokZoneId = ZoneId.of("America/New_York");
    System.out.println("TimeZone : " + newYokZoneId);

    ZonedDateTime nyDateTime = asiaZonedDateTime.withZoneSameInstant(newYokZoneId);
    System.out.println("Date (New …
Run Code Online (Sandbox Code Playgroud)

datetime java-8

3
推荐指数
1
解决办法
4179
查看次数

标签 统计

datetime ×1

java-8 ×1