forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTime.java
29 lines (24 loc) · 900 Bytes
/
DateTime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.rampatra.java8;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
/**
* @author rampatra
* @since 2019-05-15
*/
public class DateTime {
private static long getCurrentTimestampFromInstant() {
return Instant.now().toEpochMilli();
}
private static String addTwoDays() {
LocalDateTime now = LocalDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
LocalDateTime afterTwoDays = now.plusDays(2);
return afterTwoDays.getDayOfMonth() + "-" + afterTwoDays.getMonthValue() + "-" + afterTwoDays.getYear();
}
public static void main(String[] args) {
System.out.println("Timestamp from Instant: " + getCurrentTimestampFromInstant() +
"\nTimestamp from Legacy Date: " + new Date().getTime());
System.out.println("Add Two days: " + addTwoDays());
}
}