Given milliseconds. The task is to write a program in Java to convert Milliseconds to a Date which Displays the date in dd MMM yyyy HH:mm:ss:SSS Z format.
The Date class in Java internally stores Date in milliseconds. So any date is the number of milliseconds passed since January 1, 1970, 00:00:00 GMT and the Date class provides a constructor which can be used to create Date from milliseconds.
The SimpleDateFormat class helps in formatting and parsing of data. We can change the date from one format to other. It allows the user to interpret string date format into a Date object. We can modify Date accordingly.
Constructors of SimpleDateFormat:
- SimpleDateFormat(String pattern_arg) : Constructs a Simple Date Format using the given pattern – pattern_arg, default date format symbols for the default FORMAT locale.
- SimpleDateFormat(String pattern_arg, Locale locale_arg) : Constructs a Simple Date Format using the given pattern – pattern_arg, default date format symbols for the given FORMAT Locale – locale_arg.
- SimpleDateFormat(String pattern_arg, DateFormatSymbols formatSymbols) : Constructs a SimpleDateFormat using the given pattern – pattern_arg and date format symbols.
Below is the program to convert milliseconds to a Date Format in Java:
01 Jan 1970 00:00:03:010 +0000
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Java | Date format validation using Regex
- DateFormat format(Date obj) method in Java
- Convert String to Date in Java
- Python program to convert time from 12 hour to 24 hour format
- Program to convert time from 12 hour to 24 hour format
- Program to Convert List to Map in Java
- Program to Convert Set to List in Java
- Program to convert Array to Set in Java
- Java program to convert Currency using AWT
- Program to convert a Map to a Stream in Java
- Program to Convert List to Stream in Java
- Program to convert ArrayList to LinkedList in Java
- Program to convert a Set to Stream in Java using Generics
- Program to convert set of String to set of Integer in Java
- Program to Convert Stream to an Array in Java
- Program to Convert HashMap to TreeMap in Java
- Program to Convert a Vector to List in Java
- Program to convert String to IntStream in Java
- Java Program to convert boolean to integer
- Program to convert Array to List in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.