Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert String object to Date object? [duplicate]

Tags:

java

date

How can I convert a String object to a Date object?

I think I need to do something like this:

Date d=(some conversion ) "String "

Any help would be greatly appreciated.

like image 404
Suresh Avatar asked Oct 09 '09 12:10

Suresh


People also ask

Can we convert String to Date?

Using the Parse API With a Custom Formatter. Converting a String with a custom date format into a Date object is a widespread operation in Java. For this purpose we'll use the DateTimeFormatter class, which provides numerous predefined formatters, and allows us to define a formatter.

Can we convert String to Date in java?

If the String value that we need to convert to the Date-time type is of ISO-801 format then we can simply call DateFormat and SimpleDateFormat classes using parse() methods.


1 Answers

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    Date date = dateFormat.parse("1.1.2001");

For details refer to: SimpleDateFormat documentation

like image 185
KB22 Avatar answered Nov 01 '22 17:11

KB22