Created
May 15, 2021 11:08
-
-
Save gauravkukade/c0abb86106b161cd9b3d12de37e34cb3 to your computer and use it in GitHub Desktop.
A java program to get current date time using the java.util.Date class. Check the blog post at https://coderolls.com/get-current-date-time-in-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
/** | |
* A java program to get current date time using the java.util.Date class | |
* @author Gaurav Kukade at coderolls.com | |
* | |
*/ | |
public class DateExample { | |
public static void main(String[] args) { | |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
Date date = new Date(); | |
// print date object | |
System.out.println(date); // Sat May 15 12:21:39 IST 2021 | |
// print formated date object | |
System.out.println(simpleDateFormat.format(date)); // 15/05/2021 12:21:39 | |
// creates new Date() object using System.currentTimeMillis() | |
Date date2 = new Date(System.currentTimeMillis()); | |
System.out.println(simpleDateFormat.format(date)); // 15/05/2021 12:21:39 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment