Donate : Link
Medium Blog : Link
Applications : Link
Find several examples to get the current date, current time, current date & time, current date & time in a specific timezone in Java.
Get current Date in Java
package com.example.java.programming.datetime;
import java.time.LocalDate;
/**
* @author code.factory
*
*/
public class CurrentDateExample {
public static void main(String... args) {
LocalDate currentDate = LocalDate.now();
System.out.println("Current Date : " + currentDate);
}
}
Output :
Current Date : 2020-06-29
Get current Time in Java
package com.example.java.programming.datetime;
import java.time.LocalTime;
/**
* @author code.factory
*
*/
public class CurrentTimeExample {
public static void main(String... args) {
LocalTime currentTime = LocalTime.now();
System.out.println("Current Time : " + currentTime);
}
}
Output :
Current Time : 14:00:59.165
Get current Date and Time in Java
package com.example.java.programming.datetime;
import java.time.LocalDateTime;
/**
* @author code.factory
*
*/
public class CurrentDateTimeExample {
public static void main(String... args) {
LocalDateTime currentDateTime = LocalDateTime.now();
System.out.println("Current Date & Time : " + currentDateTime);
}
}
Output :
Current Date & Time : 2020-06-29T14:03:56.960
Get current Date and Time in a specific Timezone in Java
package com.example.java.programming.datetime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/**
* @author code.factory
*
*/
public class CurrentDateTimeExample {
public static void main(String... args) {
ZonedDateTime currentKolkataDateTime = ZonedDateTime.now(ZoneId.of("Asia/Kolkata"));
System.out.println("Current Date & Time : " + currentKolkataDateTime);
}
}
Output :
Current Date & Time : 2020-06-29T14:11:49.193+05:30[Asia/Kolkata]


some times its a pain in the ass to read what people wrote but this website is rattling user friendly! .
LikeLiked by 1 person
Thank you Spencer Susman
Please check new blog https://bit.ly/31989Yt
You’ll find best Android Apps on new blog
Download | Comment | Share
Buy Me A Coffee if you want, Find “Donate” link in Menu
LikeLike