How can I save string type into android SQLite datetime field
I've got following string "2013-04-30T00:55:25.855-07:00" from Google blogger feed. I try to save this string to SQLite datetime field as following command
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); initialValues.put(newsdatemodified, dateFormat.format(datemodified));
But I found that data cannot insert into sqlite table and no encounter any errors. Any solution will be appreciated.
When I've tried to use following coding
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date date1 = (Date) dateFormat.parse(entry.updated);
but following this error
05-02 09:56:05.383: E/AndroidRuntime(31634): Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
It seems that issue is with the format. May be, you can try using yyyy-MM-dd'T'HH:mm:ss.SSSZ. SSS stands for fractional seconds and Z stands for time zone.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Hope it helps else please comment. You can see other formats and try to work around with them by seeing here.
Your format is wrong, it needs to me yyyy-MM-dd'T'HH:mm:ss.SSSZ
as you can see the format you had does not match what the incoming string format was