0

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.

Update

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
PPShein
  • 13,309
  • 42
  • 142
  • 227

2 Answers2

2

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

tyczj
  • 71,600
  • 54
  • 194
  • 296
0

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.

Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • 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 – PPShein May 02 '13 at 03:30
  • Try casting it as [follows](http://stackoverflow.com/questions/530012/how-to-convert-java-util-date-to-java-sql-date). See if this works. – Shobhit Puri May 02 '13 at 03:33