如何转换毫秒迄今在SQLite的 [英] How to convert milliseconds to date in SQLite

查看:1135
本文介绍了如何转换毫秒迄今在SQLite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储日期从Calendar.getTimeInMilliseconds()中的SQLite数据库。 我需要每月在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆