Atra Wanderer
Atra Wanderer

Reputation: 35

DateFormat To DateTimeFormatter

I can get rid of this issue, and i don't found the answer rigth now.

Is it possible to convert DateFormat on DateTimeFormatter?

DateFormat dateFormat =  new SimpleDateFormat("MM/dd/yy HH:mm:ss", Locale.getDefault);

I want to make something like that :

DateTimeFormatter.ofPattern((String)dateFormatter);

Or

(DateTimeFormatter)dateFormatter;

Or is there a way to get the String that make the format in the DateFormat?

I want to do that beacause i've read that the DateTimeFormater is the Java8+ new way to deal with Date, and i need to keep the old one because it's used a lot of times elswhere in the Project.

Thanks!

Upvotes: 2

Views: 2502

Answers (1)

pkgajulapalli
pkgajulapalli

Reputation: 1126

You can use following code.

 DateTimeFormatter dateTimeFormatter = 
    DateTimeFormatter.ofPattern(((SimpleDateFormat) dateFormat).toPattern());

Upvotes: 5

Related Questions