铸造和日期选择器和时间选择器在Android中获得价值 [英] Casting and getting values from date picker and time picker in android
问题描述
我有一个的DatePicker
和 TimePicker
在我的应用程序。谁能告诉我怎么去的日期和时间所选择的值???我的意思是说,用于的EditText
我们可以声明为
I have a DatePicker
and a TimePicker
in my app. Can anyone tell me how to get the values of the date and time that are selected??? What i mean to say is, for EditText
we can declare as
final EditText name = (EditText) this.findViewById(R.id.nametext);
和我们可以通过 name.getText()投出的数据。的toString()
。
那么同样我们如何能得到的DatePicker和TimePicker的价值观为String ???
So similarly how can we get the values of DatePicker and TimePicker to a String???
推荐答案
DatePicker的有
DatePicker has
getYear()
getMonth()
getDayOfMonth()
,使从一个datepicker一个Date对象你会做新的日期(datePicker.getYear() - 1900年,datePicker.getMonth(),datePicker.getDayOfMonth());
注意,此构造是<一个href="http://developer.android.com/reference/java/util/Date.html#Date%28int,%20int,%20int%29">de$p$pcated在API级别1 - 请<一href="http://stackoverflow.com/questions/2592499/casting-and-getting-values-from-date-picker-and-time-picker-in-android/14590203#14590203">refer到andrescanavesi的回答创建Date对象的一个更合适的方式。
Note that this constructor was deprecated in API level 1 - please refer to andrescanavesi's answer for a more appropriate way of creating a Date object.
TimePicker有
TimePicker has
getCurrentHour()
getCurrentMinute()
这篇关于铸造和日期选择器和时间选择器在Android中获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!