File tree Expand file tree Collapse file tree
java8Tutorials/src/main/java/java8/time Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package java8 .time ;
2+
3+ import java .time .Clock ;
4+ import java .time .Instant ;
5+ import java .time .LocalTime ;
6+ import java .time .ZoneId ;
7+ import java .time .format .TextStyle ;
8+ import java .time .temporal .ChronoUnit ;
9+ import java .util .Date ;
10+ import java .util .Locale ;
11+
12+ public class LocalDateDemo2
13+ {
14+ public static void main (String [] args )
15+ {
16+ // get the current time
17+ Clock clock = Clock .systemDefaultZone ();
18+ long t0 = clock .millis ();
19+ System .out .println (t0 );
20+
21+ Instant instant = clock .instant ();
22+ Date legacyDate = Date .from (instant );
23+
24+
25+ ZoneId zone1 = ZoneId .of ("GMT" );
26+ ZoneId zone2 = ZoneId .of ("Brazil/East" );
27+
28+
29+ // time
30+ LocalTime now1 = LocalTime .now (zone1 );
31+ LocalTime now2 = LocalTime .now (zone2 );
32+
33+ System .out .println (now1 );
34+ System .out .println (now2 );
35+
36+ System .out .println (now1 .isBefore (now2 )); // false
37+
38+ long hoursBetween = ChronoUnit .HOURS .between (now1 , now2 );
39+ long minutesBetween = ChronoUnit .MINUTES .between (now1 , now2 );
40+ System .out .println (hoursBetween );
41+ System .out .println (minutesBetween );
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments