通过ContentValues​​插入时间戳到SQLite的 [英] Insert timestamp into SQLite via ContentValues

查看:357
本文介绍了通过ContentValues​​插入时间戳到SQLite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的:是有可能使用插入时间戳到SQLite数据库 ContentValues​​

In Android: is it possible to insert a timestamp into a SQLite database using ContentValues?

当我尝试添加它使用类似

When I try to add it using something like

ContentValues args = new ContentValues();       
args.put(MY_DATE, my_date);

我得到一个错误,告诉我​​, my_date 必须是一个字符串

推荐答案

无论是日期日历是有效的事情把在<一href="http://developer.android.com/reference/android/content/ContentValues.html"><$c$c>ContentValues.最有效的形式,我觉得,是对日期转换为毫秒(的getTime()),并存储在一个 INTEGER 列。

Neither Date nor Calendar are valid things to put in a ContentValues. The most efficient format, I think, is to convert the Date to milliseconds (getTime()) and store that in an INTEGER column.

这篇关于通过ContentValues​​插入时间戳到SQLite的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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