How Convert String to datetime in android
You can use SimpleDateFormat
for parsing String to Date.
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
try {
Date d = sdf.parse("20130526160000");
} catch (ParseException ex) {
Log.v("Exception", ex.getLocalizedMessage());
}
Now you can convert your Date
object back to String in your required format as below.
sdf.applyPattern("dd MMM yyyy hh:mm");
System.out.println(sdf.format(d));
You can use the following way.
String strDate = "2013-05-15T10:00:00-0700";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
Date date = dateFormat.parse(strDate);
System.out.println(date);
Output is : Wed May 15 10:00:00 IST 2013
I hope this will help you.