通过 ContentValues 将时间戳插入数据库
在Android中,是否可以使用ContentValues将时间戳插入数据库?当我尝试使用以下内容添加它时:
ContentValues args = new ContentValues();
args.put(MY_DATE, my_date);
我收到一条错误,告诉我 my_date
需要是 String
。关于如何实现这一目标有什么建议吗?
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);
I get an error telling me that my_date
needs to be a String
. Any suggestions on how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Date
和Calendar
都不是放入ContentValues
。我认为最有效的格式是将Date
转换为毫秒 (getTime()
) 并将其存储在INTEGER
列中。Neither
Date
norCalendar
are valid things to put in aContentValues
. The most efficient format, I think, is to convert theDate
to milliseconds (getTime()
) and store that in anINTEGER
column.