File tree 1 file changed +29
-0
lines changed
src/main/java/com/rampatra/java8
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .rampatra .java8 ;
2
+
3
+ import java .time .Instant ;
4
+ import java .time .LocalDateTime ;
5
+ import java .time .ZoneId ;
6
+ import java .util .Date ;
7
+
8
+ /**
9
+ * @author rampatra
10
+ * @since 2019-05-15
11
+ */
12
+ public class DateTime {
13
+
14
+ private static long getCurrentTimestampFromInstant () {
15
+ return Instant .now ().toEpochMilli ();
16
+ }
17
+
18
+ private static String addTwoDays () {
19
+ LocalDateTime now = LocalDateTime .ofInstant (Instant .now (), ZoneId .of ("UTC" ));
20
+ LocalDateTime afterTwoDays = now .plusDays (2 );
21
+ return afterTwoDays .getDayOfMonth () + "-" + afterTwoDays .getMonthValue () + "-" + afterTwoDays .getYear ();
22
+ }
23
+
24
+ public static void main (String [] args ) {
25
+ System .out .println ("Timestamp from Instant: " + getCurrentTimestampFromInstant () +
26
+ "\n Timestamp from Legacy Date: " + new Date ().getTime ());
27
+ System .out .println ("Add Two days: " + addTwoDays ());
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments