Format integer to formatted date in an SQLite select statement

后端 未结 3 1011
梦如初夏
梦如初夏 2020-12-19 13:08

I have an SQLite database within my Android application, which stores dates as integers. These integers are derived from a call to Java.util.Date.getTime();. I

3条回答
  •  醉梦人生
    2020-12-19 13:58

    SELECT strftime("%m-%d-%Y", date_col, 'unixepoch') AS date_col
    

    Your code will work if it expects a result set column in that format called date_col.

    EDIT: One thing you need to watch out for is that getTime uses milliseconds since 1970, while standard UNIX time (including SQLite) uses seconds.

提交回复
热议问题