Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c24e35

Browse files
committed
Some basic date time api usage (introduced in Java 8)
1 parent e4db572 commit 8c24e35

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
"\nTimestamp from Legacy Date: " + new Date().getTime());
27+
System.out.println("Add Two days: " + addTwoDays());
28+
}
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /