在SQLite数据库Android的插入日期时间 [英] Inserting datetime in sqlite database android

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

问题描述

我怎么可以插入datetime数据使用我的SQLite数据库contentvalues​​不使用原始查询?

how can i insert datetime data in my sqlite database using contentvalues not using raw query?.

日期时间('现在')插入本身(文本)而不是时间,我可以添加addittional小时到当前的时间?

datetime('now') insert itself(text) not the time, and can i add addittional hours to the current time?

样,当我preSS按钮1小时,将插入CURRENTTIME + 1小时的sqlite的database..thanks,有点迷茫..

like, when i press button "1HOUR" it would insert the currenttime + 1 hour in the sqlite database..thanks, kinda confused..

推荐答案

转换日期/时间以毫秒为单位,你会得到一个。然后你只需要插入数据库中的值。

Convert date/time to milliseconds and you get a long. Then you just insert the long value in database.

如果他们是在毫秒您可以添加日期/时间值在一起。

You can add date/time values together if they are in milliseconds.

- 编辑 -

    Date myDate = new Date();
    long timeMilliseconds = myDate.getTime();
    //add 1 hour
    timeMilliseconds = timeMilliseconds + 3600 * 1000; //3600 seconds * 1000 milliseconds
    //To convert back to Date
    Date myDateNew = new Date(timeMilliseconds);

在SQLite的java的值存储为一个 INT

In SQLite the java long value is stored as a int.

这篇关于在SQLite数据库Android的插入日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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