- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Samual Sam has Published 2492 Articles
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
88 Views
System.out.format is used in Java to format output.Firstly, create a Calendar object −Calendar calendar = Calendar.getInstance();Now, use theDate-Time conversion characters to get the date, month and year −System.out.format("%te %tB, %tY%n", calendar, calendar, calendar);The following is the complete example −Example Live Demoimport java.util.Locale; import java.util.Calendar; public class TestFormat { public static ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
339 Views
Firstly, set the locale −Locale[] strLocales = { US, UK, GERMANY};Now, let us set the date formats i.e. different constants −int[] constants = { SHORT, MEDIUM, LONG }; String[] str = { "SHORT", "MEDIUM", "LONG" };Loop through and get the different date formats for different countries −for (Locale country : ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
137 Views
Firstly, set the time with SimpleDateFormat classFormat dateFormat = new SimpleDateFormat("h:m:s");Now, for custom format, let us fetch the hour, minute and second individuallyHour// hour dateFormat = new SimpleDateFormat("h"); String strHour = dateFormat.format(new Date()); System.out.println("Hour: "+strHour);Minute// minute dateFormat = new SimpleDateFormat("m"); String strMinute = dateFormat.format(new Date()); System.out.println("Minute: "+strMinute);Second// second dateFormat = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
1K+ Views
To list short months, use the getShortMonths() from the DateFormatSymbols class in Java.DateFormatSymbols is a class for encapsulating localizable date-time formatting data.Get short month names in an arrayString[] months = new DateFormatSymbols().getShortMonths();Display the monthsfor (int i = 0; i < months.length - 1; i++) { String month = months[i]; System.out.println("Month ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
2K+ Views
Use the SimpleDateFormat class to display time in 12-hour format.Set the formatDate dt = new Date(); SimpleDateFormat dateFormat; dateFormat = new SimpleDateFormat("hh:mm:ss a");Now, the following will display time in 12-hour formatdateFormat.format(dt)The following is an exampleExample Live Demoimport java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String[] argv) throws ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
177 Views
The SimpleDateFormat class is used to parse and format dates. To create an object, firstly import the following packageimport java.text.SimpleDateFormat;Set the dateString strDate = "'Year = '"; strDate += "yyyy"; strDate += "'Month = '"; strDate += "MMMMMMMMM"; strDate += "'Hours = '"; strDate += "hh"; strDate += "a"; strDate ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
257 Views
DateFormat.FULL is a constant for full style pattern.Firstly, we will create Date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.FULL −// FRENCH dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. FULL, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
151 Views
Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.MEDIUM is a constant for medium style pattern.Firstly, we will create a Date object −Date dt = new Date(); DateFormat dateFormat;Let us format time for a different locale with DateFormat.MEDIUMdateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.CANADA); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
355 Views
Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.FULL is a constant for full style pattern.Firstly, we will create Date objectDate dt = new Date(); DateFormat dateFormat;Let us format time for different locale with DateFormat.FULLdateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CHINESE); System.out.println("Locale CHINESE = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
183 Views
Create a SimpleDateFormat object −SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");Do not forget to import the following package for SimpleDateFormat class −import java.text.SimpleDateFormat;Now, since we have set the format for date above, let us parse the date using parseObject() method −Date dt = (Date) dateFormat.parseObject("2018.11.22.11.50.15");The following is an example −Example Live Demoimport java.util.Date; ... Read More