使用时间选择器 android 获取时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22294040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:47:17  来源:igfitidea点击:

Get time using time picker android

androidtimepicker

提问by Sharjeel

How can I simply get time, set by the user on time picker widget in android ?

我怎样才能简单地获取时间,由用户在 android 中的时间选择器小部件上设置?

Like this.

像这样。

timepicker.gettime();

回答by user3395743

Try it like below.

像下面一样尝试。

For picking hour you can use

对于采摘时间,您可以使用

timePicker.getCurrentHour();

and for picking minutes you can use

和挑选分钟,你可以使用

timePicker.getCurrentMinute();

and then you can set this hour and minute to any Integer variable. Like

然后您可以将此小时和分钟设置为任何整数变量。喜欢

int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();

for more information you can refer to this link

有关更多信息,您可以参考此链接

http://www.mkyong.com/android/android-time-picker-example/

http://www.mkyong.com/android/android-time-picker-example/

回答by reza.cse08

If you are using below API 23. then you can use

如果您使用的是低于 API 23. 那么您可以使用

int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();

And after 23 you can use both

在 23 之后,您可以同时使用

int hour = timePicker.getHour();
int minute = timePicker.getMinute();