InterviewSolution
Saved Bookmarks
| 1. |
How to format a date in Java? |
|
Answer» The methods to FORMAT the data in Java are provided in the class java.text.SimpleDateFormat. This class is a concrete class that is used for formatting and parsing the date and it inherits from the java.text.DateFormat class. A program to format the date in Java using the java.text.SimpleDateFormat is given as FOLLOWS: import java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void MAIN(String[] args) { Date d = new Date(); SimpleDateFormat SDformat = new SimpleDateFormat("dd / MM / yy"); String curDate = SDformat.format(d); System.out.println("The date is: " + curDate); } }The OUTPUT of the above program is as follows: The date is: 14 / 12 / 18 |
|