My server response "Nov 27, 2011 07:00am". Then I put this variable.
String fecha="Nov 27, 2011 07:00am"
but I need in this format:
String fecha="2014-11-27 07:00am";
Then I want to save this string in SQLite as Date.
How can I resolve this?
My server response "Nov 27, 2011 07:00am". Then I put this variable.
String fecha="Nov 27, 2011 07:00am"
but I need in this format:
String fecha="2014-11-27 07:00am";
Then I want to save this string in SQLite as Date.
How can I resolve this?
In sqllite you cannot store date and time directly, so you are left with 2 options
1) Convert it into milliseconds
2)Save it as a string.
I personally prefer the first one as it it more elite, here's the code to do the above .
public static long convertDateToMilliSeconds(String inputDate){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
Date date = null;
try {
date = simpleDateFormat.parse(inputDate);
} catch (ParseException e) {
e.printStackTrace();
//throw new IllegalAccessException("Error in parsing date");
}
return date.getTime();
}
public static Date convertMilliSecondToDate(long milliSeconds){
Date date= new Date(milliSeconds);
return date;
}
Read this doc about SimpleDateFormat and parsing Date Time. You can even use a longer route that involves splitting the string, and re-arranging it into the format that you desire.