Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Equivalent to .NET's DateTime.Parse?

I'm working on a java class that I will use with Pervasive Data Profiler that needs to check if a Date String will work with .NET's DateTime.Parse.

Is there an equivalent class or 3rd party library that can give me this functionality that is very close to .NET's DateTime.Parse?

I would need it to be able to handle a broad range of date formats. ex. "12/20/2008", "1/1/08", "5/10/2009 12:46:00 AM", "5/10/2009 17:46:00"

like image 554
RoboDev Avatar asked Mar 15 '10 21:03

RoboDev


2 Answers

See parse method in DateFormat Class. Here is a sample

DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
Date date = df.parse("2001-01-01");
like image 113
Asad Avatar answered Oct 07 '22 17:10

Asad


Check the DateFormat.parse(String) methods of the DateFormat class.

Also, the class Date has two deprecated methods that parse strings into Date objects, however the use of the Date class in general is not recommended. It has been replaced by the Calendar class.

like image 32
pnt Avatar answered Oct 07 '22 16:10

pnt