- 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
Java Program to format date as Apr 14 2019 01:35 PM IST
To format and display datetime, you need to use DateTimeFormatter and use the pattern as:
DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");
Above, the z is the timezone:
MMM dd yyyy hh:mm a z
Now, use the following for zone:
ZonedDateTime dateTime = ZonedDateTime.now();
Example
import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; public class Demo { public static void main(String[] argv) { DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z"); ZonedDateTime dateTime = ZonedDateTime.now(); String res = dateTime.format(dtFormat); System.out.printf("Date = %s %n", res); } }
Output
Date = Apr 14 2019 01:35 PM IST
Advertisements