- 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 34494 Articles for Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
199 Views
To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“hh”) to display hour −Format f = new SimpleDateFormat("hh");Now, get the hour in a string −String strHour = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
178 Views
To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;To get the date, use the format() method as shown below. Firstly, set the date format −Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy");Now, we will get the date −simpleformat.format(cal.getTime())The following is the complete example −Example Live Demoimport java.text.SimpleDateFormat; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
353 Views
Firstly, create a formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display complete date and time information uses the ‘c’ conversion character. However, to display it in uppercase, use ‘Tc’.f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc", cal));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
113 Views
Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display complete date and time information use the ‘c’ conversion character. However, to display it in lowercase, use ‘tc’ −f = new Formatter(); System.out.println(f.format("Date and Time (lowercase): %tc", cal));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
241 Views
Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();For AM/ PM marker, use the following conversion character −pHere, you can see AM/ PM marker −f = new Formatter(); System.out.println(f.format("Hour: %tl %1$Tp", c));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); System.out.println("Current date and time: "+c.getTime()); f ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
164 Views
Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display hour using Formatter class, use the ‘l’ conversion a character −f = new Formatter(); System.out.println(f.format("Hour: %tl", c));To display minute using Formatter class, use the ‘M’ conversion character −f = new Formatter(); System.out.println(f.format("Minute: %1$tM", c));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
103 Views
Firstly, create a Formatter and Calendar object.Formatter f = new Formatter(); Calendar cal = Calendar.getInstance();Now display the current date and time. We have shown the date here in both lowercase and uppercase −f = new Formatter(); System.out.println(f.format("Date and Time (lowercase): %tc", cal)); f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc", cal));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“mm”) to display minutes in two-digits.Format f = new SimpleDateFormat(‘”mm”);Now, get the minutes in a string.String strMinute = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
110 Views
To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“m”) to display minutes.Format f = new SimpleDateFormat(‘”m”);Now, get the minutes in a string.String strMinute = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
324 Views
To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“H”) to display hour in a day.Format f = new SimpleDateFormat("H");Now, get the hour −String strHour = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More