Skip to content

Commit ba4fb5b

Browse files
committed
Add sample code to get current time in Java 8
1 parent ef54cd4 commit ba4fb5b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.util;
2+
3+
import java.time.LocalDateTime;
4+
import java.time.LocalTime;
5+
import java.time.ZoneId;
6+
7+
public class GetCurrentTime {
8+
9+
public static void main(String args[]) {
10+
11+
LocalTime localTime = LocalTime.now();
12+
System.out.println("Current time is: " + localTime);
13+
14+
localTime = LocalTime.now(ZoneId.of("GMT+02:30"));
15+
System.out.println("Current time in GMT +02:30 timezone: " + localTime);
16+
17+
LocalDateTime localDateTime = LocalDateTime.now();
18+
System.out.println("Current time is: " + localDateTime.toLocalTime());
19+
}
20+
}

0 commit comments

Comments
 (0)