Skip to content

Commit 2b0a864

Browse files
add LocalDateTime examples
1 parent a356fea commit 2b0a864

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package randomExamples;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.Date;
5+
6+
public class DateVsLocalDateTime {
7+
public static void main(String... args) throws InterruptedException {
8+
Date startDate = new Date();
9+
LocalDateTime startLocalDateTime = LocalDateTime.now();
10+
System.out.println("date is: " + startDate);
11+
System.out.println("localDateTime is: " + startLocalDateTime);
12+
Thread.sleep(1000);
13+
Date endDate = new Date();
14+
LocalDateTime endLocalDateTime = LocalDateTime.now();
15+
System.out.println("date is: " + endDate);
16+
System.out.println("localDateTime is: " + endLocalDateTime);
17+
18+
long duration1 = ((endDate.getTime() - startDate.getTime()) / 1000);
19+
long duration2 = (endLocalDateTime.getSecond() - startLocalDateTime.getSecond());
20+
System.out.println("duration1 is: " + duration1);
21+
System.out.println("duration2 is: " + duration2);
22+
}
23+
}

0 commit comments

Comments
 (0)