Change Gregorian Calendar to SimpleDateFormat in Java
Input: Sat Apr 28 13:36:37 UTC 2018 Output: 28-Apr-2018 Input: Wed Apr 03 20:49:45 IST 2019 Output: 03-Apr-2019
- Get the Gregorian Date to be converted.
- Create an object of SimpleDateFormat that will store the converted date
- Now change the Gregorian Date into SimpleDateFormat using the format() method.
- This format method will take the only the date part of Gregorian date as the parameter. Hence using getTime() method, this required date is passed to format() method.
Below is the implementation of the above approach:
Gregorian date: Wed Apr 03 05:21:17 UTC 2019 SimpleDateFormat: 03-Apr-2019
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.