Java: convert birth data to days

后端 未结 4 563
春和景丽
春和景丽 2021-01-17 06:11

I really need some help with the specific assignment. The user inputs birth data (YYYY MM DD) and the program tells you how old you are in days :

The outprint in co

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 06:58

    java.time

    In Java 8 and later, you could use the java.time classes such as ChronoUnit and LocalDate. Perhaps not appropriate to a homework assignment though.

    long days = ChronoUnit.DAYS.between( LocalDate.parse( "1981-11-06" ) , LocalDate.now( ZoneId.of( "America/Montreal" ) ) ) ;
    

提交回复
热议问题