/* now() */
LocalDateTime dateNow = LocalDateTime.now();
System.out.println( dateNow );
System.out.println( dateNow.format( DateTimeFormatter.ofPattern( "dd.MM.yyyy H:m:s" ) ) );
/* defined datetime 1. Jan 2018 17:00 h */
LocalDateTime date = LocalDateTime.of( 2018, 1, 1, 17, 0, 0 );
System.out.println( date.format( DateTimeFormatter.ofPattern( "dd.MM.yyyy H:m:s" ) ) );
/* ..add 25 minutes to previous */
LocalDateTime dateend = date.plusMinutes( 25 );
System.out.println( dateend.format( DateTimeFormatter.ofPattern( "dd.MM.yyyy H:m:s" ) ) );
/* ..and check difference in minutes */
System.out.println( date.until( dateend, MINUTES ) );
Output:
2018-11-28T09:50:58.724
28.11.2018 9:50:58
01.01.2018 17:0:0
01.01.2018 17:25:0
25
No comments:
Post a Comment