Some Java Guy
Some Java Guy

Reputation: 5118

Simple Date Format for string

I have my current data as 2012-08-20T12:30:00+05:30

  DateTime currentdata = "2012-08-20T12:30:00+05:30";

I am using

 String myDate = new SimpleDateFormat("MM/dd/yyyy").format(currentdata);

I get Cannot format given Object as a Date

Any clues??

Upvotes: 2

Views: 9666

Answers (2)

Sai Ye Yan Naing Aye
Sai Ye Yan Naing Aye

Reputation: 6738

 String myDate = new SimpleDateFormat("MM/dd/yyyy").format(currentdata);

According to this line, currentdata may access String or Object.

  DateTime currentdata = "2012-08-2012:30:00+05:30";

According to this line, current data may be Object.This is error point.'format' method access Date object.Change your data type.If you don't want to change this, change your currentdata (2012-08-20T12:30:00+05:30) to (2012-08-2012 30:05:30). If you won't, illegal argument exception may be occured.

Upvotes: 0

AxxA Osiris
AxxA Osiris

Reputation: 1209

String myDate = new SimpleDateFormat("MM/dd/yyyy").format(currentdata.toDate());

Upvotes: 4

Related Questions