通过ContentValues将时间戳插入数据库 [英] Insert a time stamp into database via ContentValues

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

问题描述

在Android中,是否可以使用 ContentValues 将时间戳插入数据库?当我尝试使用以下内容添加它时:

In Android, is it possible to insert a time stamp into a database using ContentValues? When I try to add it using something like this:

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

我收到错误告诉我 my_date 需要是 String 。关于如何实现这一点的任何建议?

I get an error telling me that my_date needs to be a String. Any suggestions on how to achieve this?

推荐答案

日期也不日历是放在 ContentValues 。我认为,最有效的格式是将 Date 转换为毫秒( 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将时间戳插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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