How to create Java time instant from pattern?

后端 未结 4 1045
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 01:51

Consider a code:

TemporalAccessor date = DateTimeFormatter.ofPattern(\"yyyy-MM-dd\").parse(\"9999-12-31\");
Instant.from(date);

The last line t

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 02:19

    public static void main(String[] args) throws ParseException {
            System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2016-12-31").toInstant());
    }
    

    the above code gives the following output:

    2016-12-31T00:00:00Z

    i have answered this question using features('toInstant' method) of java 8. hope this answers your question...

提交回复
热议问题