- 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 parse Time using custom format
To get the time format, use the DateFormat class and create a new object.
DateFormat dateFormatter = new SimpleDateFormat("hh.mm.ss a");
Now, parse the time.
dateFormatter.parse("12.55.20 PM");
Example
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) throws Exception { DateFormat dateFormatter = new SimpleDateFormat("hh.mm.ss a"); System.out.println("Parse Time..."); Date dt = (Date) dateFormatter.parse("12.55.20 PM"); System.out.println(dt); } }
Output
Parse Time... Thu Jan 01 12:55:20 UTC 1970
Advertisements