LocalTime from Date

后端 未结 4 1896
有刺的猬
有刺的猬 2020-12-18 23:09

I\'m trying to convert a Date instance to a LocalTime instance.

// Create the Date
Date date = format.parse(\"2011-02-18 05:00:00.0         


        
4条回答
  •  遥遥无期
    2020-12-18 23:22

    Try this

        String datestring = "2011-02-18 05:00:00.0";
        SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//take a look at MM
        Date date = dt.parse(datestring );
        Instant instant = Instant.ofEpochMilli(date.getTime());
        LocalTime res = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalTime();
    

提交回复
热议问题