Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting time and date to date picker and time picker in android

I am using a date picker and time picker in my application. I want to set the date and time when the page loads. Is this possible? How so?

like image 792
andro-girl Avatar asked Apr 28 '11 11:04

andro-girl


People also ask

How do I add time to a date picker?

Display the current date and time in a date pickerClick the Data tab. In the Data type box, click Date and Time (dateTime). Click Format. In the Date and Time Format dialog box, in the Display the time like this list, click the option that you want, and then click OK.

What is date picker and time picker in Android?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).

What are the modes available in date and time picker?

Example: DateTimePicker in ReactNative The options are date, time, datetime and countdown. From above options datetime and countdown are available only on iOS. The values for Android are default, spinner, calendar and clock.

How can you use time picker in Android application?

Android Time Picker allows you to select the time of day in either 24 hour or AM/PM mode. The time consists of hours, minutes and clock format. Android provides this functionality through TimePicker class.


1 Answers

I solved a similar problem of mine as follows

Calendar cal = Calendar.getInstance();  int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int min = cal.get(Calendar.MINUTE);  datePicker.updateDate(year, month, day);  timePicker.setCurrentHour(hour); timePicker.setCurrentMinute(min); 
like image 58
yildirimyigit Avatar answered Oct 13 '22 16:10

yildirimyigit