Android : Convert String to Date and Date to String
From String to Date
String dtStart = "2010-10-15T09:27:37Z"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); try { Date date = format.parse(dtStart); System.out.println(date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
From Date to String
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); try { Date date = new Date(); String datetime = dateFormat.format(date); System.out.println("Current Date Time : " + datetime); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
ที่มา: http://stackoverflow.com/questions/8573250/android-how-can-i-convert-string-to-date