如何从日期选择器获取毫秒? [英] How to get milliseconds from a date picker?

查看:209
本文介绍了如何从日期选择器获取毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我在sqllite数据库中保存了几毫秒,默认情况下,我正在保存

In my project I am saving milliseconds in a sqllite databse, by default I am saving

System.currentTimeMillis()

数据库中的

,但是用户是否可以从日期选择器中选择以前的日期?但是,当用户从日期选择器中选择前一个或以后的几天时,我可以保存什么呢?如何获得长格式(毫秒)的那一天?

in the database, but there is an option for the user to select previous date from a date picker? But what sould I save then when user selects a previous or up comming days from the date picker? How can I get that day as a long(milliseconds) format?

推荐答案

创建一个Calender实例并设置所需的日期.然后调用calendar.getTimeInMillis();.请参见的答案所以问题以获取更多信息.

Create a Calender instance and set the date you want. Then call calendar.getTimeInMillis();. See the answer of this previous SO question for more information.

编辑:要设置日历日期,您可以使用以下方法:

EDIT To set the calendar date you can use something like this:

//Lets suppose you have a DatePicker instance called datePicker
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
cal.set(Calendar.MONTH, datePicker.getMonth());
cal.set(Calendar.YEAR, datePicker.getYear());

有关更多信息,请参见日历类.

See the Calendar class for more information.

这篇关于如何从日期选择器获取毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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