Skip to content

Commit 1059276

Browse files
committed
added LocalDateDemo2.java
1 parent 62b904e commit 1059276

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)