- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Convert string of time to time object in Java
Here is our string.
String strTime = "20:15:40";
Now, use the DateFormat to set the format for date.
DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
Parse the string of time to time object.
Date d = dateFormat.parse(strTime);
The following is the complete example.
Example
import java.text.DateFormat; import java.util.Date; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) throws Exception { String strTime = "20:15:40"; DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss"); Date d = dateFormat.parse(strTime); System.out.println("Resultant Date and Time = " + d); } }
Output
Resultant Date and Time = Thu Jan 01 20:15:40 UTC 1970
- Related Articles
- How to convert ISO 8601 string to Date/time object in Android?
- How to convert string to time in MySQL?
- How to convert ISO 8601 String to Date/Time object in Android using Kotlin?
- Convert the Current Time to a java.sql.Date Object
- Pandas program to convert a string of date into time
- Convert Java String Object to Boolean Object
- How to convert varchar “time” to real time in MySQL?
- How to convert a time series object to a vector in R?
- Java Program to Convert the local Time to GMT
- Add time to string data/time - JavaScript?
- How to convert a datetime string to millisecond UNIX time stamp?
- Java Program to convert Java String to Float Object
- Convert the value of the current DateTime object to a Windows file time in C#
- Parse string date time value input in Java
- How to access and convert time using the time library in Python

Advertisements