Android Set time and date

Source: Internet
Author: User

When an input box needs to fill in a time or a date can be called

Date settings

This is the date button for the listener, click to appear as shown in
Datebn.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View source) {Calendar C=calendar.getinstance (); //create an instance of the Datepickerdialog dialog box directly and display it NewDatepickerdialog (datedialogtest. This, //Binding Listeners NewDatepickerdialog.ondatesetlistener () {@Override Public voidOndateset (DatePicker DP,intYear ,intMonthintdayofmonth) {EditText Show=(EditText) Findviewbyid (r.id.show); Show.settext ("You have selected:" + year + "years" + (month + 1) + "Month" + DayOfMonth + "Day"); } } //set the initial date, C.get (calendar.year), C.get (Calendar.month), C.get (calendar.day_of_m Onth)). Show (); } });

Time setting

        //binds the listener for the Set time button. Timebn.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View source) {Calendar C=calendar.getinstance (); //Create a Timepickerdialog instance and display it.                 NewTimepickerdialog (datedialogtest. This,                    //Binding Listeners                    NewTimepickerdialog.ontimesetlistener () {@Override  Public voidOntimeset (timepicker TP,intHourofday,intminute) {EditText Show=(EditText) Findviewbyid (r.id.show); Show.settext ("You have selected:" + Hourofday + "when" +minute+ "Min"); }                    }                //set the initial time, C.get (Calendar.hour_of_day), C.get (Calendar.minute)//true means a 24-hour system is used,true). Show (); }        });

Android Set time and date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.