I have an application where the user selects a date as well as a time (using DatePicker and TimePicker). Is there any way to combine all the values into one integer? Both the DatePicker and TimePicker return integers, if I add them up, will the value then be the selected date and time, or does it need to be done some other way?
我有一个应用程序,用户选择日期和时间(使用DatePicker和TimePicker)。有没有办法将所有值组合成一个整数? DatePicker和TimePicker都返回整数,如果我将它们加起来,那么值是选定的日期和时间,还是需要以其他方式完成?
The way I've been understanding date and time, is it gives the difference in milliseconds from a certain point. Based on that, I would guess that adding the amounts together would give the correct time (taking into account the different starting times of the various methods).
我一直在理解日期和时间的方式是,它给出了从某个点开始的毫秒差异。基于此,我猜想将数量加在一起会得到正确的时间(考虑到各种方法的不同开始时间)。
Thanks!
谢谢!
1 个解决方案
#1
5
You can use a Calendar, set the components then get the date.
您可以使用日历,设置组件然后获取日期。
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 37);
cal.set(Calendar.DAY_OF_MONTH, 13);
cal.set(Calendar.MONTH, Calendar.JANUARY);
Date d = cal.getTime();
long time = cal.getTimeInMillis();
#1
5
You can use a Calendar, set the components then get the date.
您可以使用日历,设置组件然后获取日期。
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 37);
cal.set(Calendar.DAY_OF_MONTH, 13);
cal.set(Calendar.MONTH, Calendar.JANUARY);
Date d = cal.getTime();
long time = cal.getTimeInMillis();