通过 ContentValues 将时间戳插入数据库

发布于 2024-09-13 04:25:23 字数 247 浏览 7 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-09-20 04:25:23

DateCalendar 都不是放入 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文