如何存储在SQLite数据库在Android中的时间值? [英] how to store a time value in SQLite database in Android?

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

问题描述

我要存储一个TIMEVALUE在Android的SQLite数据库。我的时间价值是EditText上,当我点击保存按钮,我想时间值存储在数据库中。同时,我想回顾在数据库中已存储的值。

I want to store a timevalue in an SQLite database in Android. My time value is in EditText, and when I click the save button I would like the time value to be stored in the database. And also I want to review the already-stored value in the database.

推荐答案

SQLite的没有一个具体的存储时间数据类型,以及是否希望将它们存储为文本,整数或浮点数保留这些给你,所以你可以建立任何约定,你是最好的。

SQLite doesn't have a specific datatype for storing times, and leaves it up to you whether you want to store them as text, integers, or floating-point values, so you can establish whatever convention works best for you.

有关您的应用程序,你需要的时候可以编辑我会建议寻找到的的DatePicker TimePicker 的小部件,让你不必担心解析和格式化时间为文本,然后在Java 日历类从这些成一个简单的值,你可以把数据库中的转换数据(我建议使用<一个href="http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html#getTimeInMillis()">getTimeInMillis()方法将其转换成一个整数)。

For your application where you want the time to be editable by the user I'd suggest looking into the DatePicker and TimePicker widgets, so that you don't have to worry about parsing and formatting the time as text, and then the Java Calendar class for converting the data from those into a simple value that you can put in the database (I'd suggest using the getTimeInMillis() method to convert it into a integer).

这篇关于如何存储在SQLite数据库在Android中的时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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