- 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
Found 34486 Articles for Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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 = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CANADA); System.out.println("Locale CANADA = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.ITALY); System.out.println("Locale ITALY = " + dateFormat.format(dt));The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
147 Views
Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.LONG is a constant for long style pattern.Firstly, we will create Date objectDate dt = new Date(); DateFormat dateFormat;Let us format time for different locale with DateFormat.LONGdateFormat = DateFormat.getTimeInstance(DateFormat.LONG, Locale.FRENCH); System.out.println("Locale FRENCH = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, Locale.GERMANY); System.out.println("Locale GERMANY = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, Locale.CHINESE); System.out.println("Locale CHINESE = " + dateFormat.format(dt));The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
89 Views
The Float.isInfinite() method in Java returns true if this Float value is infinitely large in magnitude, else false is returned.We have the following Float valuesFloat f1 = new Float(5.0/0.0); Float f2 = new Float(10.2/0.0); Float f3 = new Float(0.0/0.0);Check with isInfinite() methodf1.isInfinite(); f2.isInfinite(); f3.isInfinite();The following is the complete example with output −Example Live Demoimport java.lang.*; public class Demo { public static void main(String args[]) { Float f1 = new Float(5.0/0.0); Float f2 = new Float(10.2/0.0); Float f3 = new Float(0.0/0.0); System.out.println(f1.isInfinite()); System.out.println(f2.isInfinite()); System.out.println(f3.isInfinite()); } }Outputtrue true false
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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); System.out.println("Locale CANADA = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.ITALY); System.out.println("Locale ITALY = " + dateFormat.format(dt));The following is an exampleExample Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
385 Views
Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.SHORT is a constant for short style pattern.Firstly, we will create Date objectDate dt = new Date(); DateFormat dateFormat;Let us format time for different locale with DateFormat.SHORTdateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.CHINESE); System.out.println("Locale CHINESE = " + dateFormat.format(dt)); dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.CANADA); System.out.println("Locale CANADA = " + dateFormat.format(dt));The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; // Date Format FULL constant dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); System.out.println("Locale FRENCH = " ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
DateFormat.SHORT is a constant for short style pattern.Firstly, we will create date objectDate dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.SHORT// FRENCH dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRENCH); // GERMANY dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMANY);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; // Date Format SHORT constant dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRENCH); System.out.println("Locale FRENCH = " + dateFormat.format(dt)); dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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 += "'Minutes = '"; strDate += "mm"; strDate += "'Seconds = '"; strDate += "ss";Now, create an object and format the date −SimpleDateFormat dateFormat = new SimpleDateFormat(strDate); String formattedDate = dateFormat.format(new Date());The following is an example −Example Live Demoimport java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
123 Views
To set a duration, let us declare two objects of Calendar classCalendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance();Set a time for one of the calendar objectsc2.add(Calendar.HOUR, 9); c2.add(Calendar.MINUTE, 15); c2.add(Calendar.SECOND, 40);Now, find the difference between both the time. One would be the current time and another we declared above −long calcSeconds = (c2.getTimeInMillis() - c1.getTimeInMillis()) / 1000;The following is an example −Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String args[]) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); // set hour, minute and second c2.add(Calendar.HOUR, 9); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
Firstly, import the following Java packages −import java.text.SimpleDateFormat; import java.util.Date;Now, create objects −Date dt = new Date(); SimpleDateFormat dateFormat;Displaying date in the format we wantdateFormat = new SimpleDateFormat("E MMM dd yyyy");The following is an example −Example Live Demoimport java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String args[]) { Date dt = new Date(); SimpleDateFormat dateFormat; dateFormat = new SimpleDateFormat("E MMM dd yyyy"); System.out.println("Date: "+dateFormat.format(dt)); } }OutputDate: Thu Nov 22 2018