I have two date format one in string "yyyy-MM-dd't'HH:mm:ss.SSSZ" and second one in long "yyyyMMddHHmmssSSS". I want to convert it into this format "yyyy-MM-dd HH:mm:ss", its convert successfully but when I print date.getTime() than
for first -> 1416490009109
for second -> 20141120121211800
code:
private DateTimeFormatter formater,formater1;
private SimpleDateFormat formate,formate1,formate2;
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
String pattern1 = "yyyy-MM-dd HH:mm:ssZ";
//String pattern = "yyyy-MM-dd HH:mm:ss";
formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formate1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
formate2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
formater = DateTimeFormat.forPattern(pattern);
formater1 = DateTimeFormat.forPattern(pattern1);
String dateTime = "2011-11-20'T'11:42:12.672+00:00";
long savePoint = 20141120114212672L;
try {
datetime = formater.parseDateTime(dateTime);
date = datetime.toDate();
//Log.d("Android: ", "Date formate: "+datetime);
dt = formate.format(date.getTime());
Log.d("Android: ", "date Keys1: "+date.getTime());
} catch (Exception e) {
Log.d("Android: ", "Error: "+e);
}
for second one
try {
String[] tzone = dateTime.split("[+]");
String times = formate1.format(Long.parseLong(savePoint));
datetime = formater.parseDateTime(times+"+"+tzone[tzone.length-1]);
date = datetime.toDate();
dt = formate.format(date.getTime());
} catch (Exception e) {
Log.d("Android:", "Error: "+e);
}