How to convert milliseconds to date in SQLite

后端 未结 3 1753
一整个雨季
一整个雨季 2020-12-01 12:32

I store date from Calendar.getTimeInMilliseconds() in SQLite DB. I need to mark first rows by every month in SELECT statement, so I need convert time in milliseconds into an

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 13:11

    One of SQLite's supported date/time formats is Unix timestamps, i.e., seconds since 1970. To convert milliseconds to that, just divide by 1000.

    Then use some date/time function to get the year and the month:

    SELECT strftime('%Y-%m', MillisField / 1000, 'unixepoch') FROM MyTable
    

提交回复
热议问题