如何在 SQLite 中将毫秒转换为日期 [英] How to convert milliseconds to date in SQLite
本文介绍了如何在 SQLite 中将毫秒转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 Calendar.getTimeInMilliseconds() 中的日期存储在 SQLite DB 中.我需要在 SELECT 语句中每个月标记第一行,所以我只需要使用 SQLite 函数将时间以毫秒为单位转换为任何日期格式.我怎样才能避免这种情况?
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 any date format using SQLite function only. How can I avoid this?
推荐答案
SQLite 支持的日期/时间格式之一 是 Unix 时间戳,即自 1970 年以来的秒数.要将毫秒转换为毫秒,只需除以 1000.
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
这篇关于如何在 SQLite 中将毫秒转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文