Add sample code to get current time in Java 8
This commit is contained in:
		
							parent
							
								
									ef54cd43cb
								
							
						
					
					
						commit
						ba4fb5bf42
					
				| @ -0,0 +1,20 @@ | ||||
| package com.baeldung.util; | ||||
| 
 | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalTime; | ||||
| import java.time.ZoneId; | ||||
| 
 | ||||
| public class GetCurrentTime { | ||||
| 
 | ||||
|     public static void main(String args[]) { | ||||
|          | ||||
|         LocalTime localTime = LocalTime.now(); | ||||
|         System.out.println("Current time is: " + localTime); | ||||
|          | ||||
|         localTime = LocalTime.now(ZoneId.of("GMT+02:30")); | ||||
|         System.out.println("Current time in GMT +02:30 timezone: " + localTime); | ||||
|          | ||||
|         LocalDateTime localDateTime = LocalDateTime.now(); | ||||
|         System.out.println("Current time is: " + localDateTime.toLocalTime()); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user