- 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
Parse string date time value input in Java
In Java, you can parse string date time value input using
SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
We have used the above class since we imported the following package −
import java.text.SimpleDateFormat;
Now, we can display the date in the same format −
Date dt = (Date) dateFormatter.parseObject("Tue, 20 Nov 2018 16:10:45 -0530");
The following is an example −
Example
import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) throws Exception { Format dateFormatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); Date dt = (Date) dateFormatter.parseObject("Tue, 20 Nov 2018 16:10:45 -0530"); System.out.println(dt); } }
Output
Tue Nov 20 21:40:45 UTC 2018
Advertisements