Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How format date in java/android

I am trying to develop an android application, regarding with that I have got some data from server.

Here I need to convert a date which comes in the given format "2013-12-31T15:07:38.6875000-05:00" I need to convert this in to a date object or a calendar object how can we do this?

I have tried with code given below. But it doesn't reach my expectation

String dateString="2013-12-31T15:07:38.6875000-05:00";
Date date = null;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
try {
    date = df.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
}
return date;
like image 521
ranjith Avatar asked Mar 15 '26 02:03

ranjith


1 Answers

Your format string doesn't match the date format you are getting. You should use the following format string:

"yyyy-MM-dd'T'HH:mm:ss.SSSX"
  • SSS is for milliseconds.
  • X is for ISO 8601 timezone
like image 184
Rohit Jain Avatar answered Mar 16 '26 14:03

Rohit Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!