后端开发|php教程
DatePicker,TimePicker,UI
后端开发-php教程
日期和时间是任何手机平台都有的功能,Android也如此。
asp 商会源码,vscode替换为tab,ubuntu pdf编辑,如何在tomcat里面,爬虫 定向,PHP中的use,推广软件seo霸屏,html5 网站开场动画,商城app html模板lzw
DatePicker:用来实现日期(年月日)
易语言模块转换源码,vscode图片插件,苹果手机安装ubuntu容器,tomcat 部署 刷新,sqlite 外键关键,防封ios红包插件,jui前端框架下载,画巨型骷髅爬虫,字符串分割 php,淘宝seo,开源网站后台管理系统使用,网页浮层,destoon 6.0模板,手机注册页面模板源码,驾校预约管理系统源码,禾匠小程序商家拼团lzw
TimePicker:用来实现时间(时分秒)
Calendar:日历是设定年度日期对象和一个整数字段之间转换的抽象基类,如,月,日,小时等。
手机版任务网源码,ubuntu U盘 流畅,怎么改tomcat编码格式,爬虫 获取起点用户,php实现在线客服插件,潍坊seo干货lzw
例如
final Calendar calendar=Calendar.getInstance();mYear=calendar.get(Calendar.YEAR);—获取年份mMonth=calendar.get(Calendar.MONTH);—获取月份mDay=calendar.get(Calendar.DAY_OF_MONTH);—获取日mHour=calendar.get(Calendar.HOUR_OF_DAY);—获取时mMinute=calendar.get(Calendar.MINUTE);—获取分
等等,可以参考API文档
TimePickerDialog、DatePickerDialog是对话框形式的时间类。
废话不多说,实例如下:
DateTest.java文件
package org.loulijun.datetest;import java.util.Calendar;import android.app.Activity;import android.app.DatePickerDialog;import android.app.TimePickerDialog;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.DatePicker;import android.widget.TextView;import android.widget.TimePicker;public class DateTest extends Activity { /** Called when the activity is first created. */ TextView textview; TimePicker timepicker; DatePicker datepicker; Button btn1; Button btn2; //JAVA中的Calendar类 Calendar c; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*Like other locale-sensitive classes, Calendar provides a class method, getInstance, *for getting a default instance of this class for general use. *Calendars getInstance method returns a calendar whose locale is based on system settings *and whose time fields have been initialized with the current date and time: */ c=Calendar.getInstance(); textview=(TextView)findViewById(R.id.textview); btn1=(Button)findViewById(R.id.button1); btn2=(Button)findViewById(R.id.button2); //获取DatePicker对象 datepicker=(DatePicker)findViewById(R.id.datepicker1); //将日历初始化为当前系统时间,并设置其事件监听 datepicker.init(c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {// TODO Auto-generated method stub//当前日期更改时,在这里设置c.set(year,monthOfYear,dayOfMonth); }}); //获取TimePicker对象 timepicker=(TimePicker)findViewById(R.id.timepicker1); //设置为24小时制显示时间 timepicker.setIs24HourView(true); //监听时间改变 timepicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {// TODO Auto-generated method stub//时间改变处理//c.set(year,month,hourOfDay,minute,second); }}); btn1.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) {// TODO Auto-generated method stubnew DatePickerDialog(DateTest.this,new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //设置日历 }},c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH)).show(); } }); btn2.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) {// TODO Auto-generated method stubnew TimePickerDialog(DateTest.this,new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {// TODO Auto-generated method stub//设置时间 }},c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),true).show(); } }); }}
main.xml文件
运行结果如下:
当点击“设置日期”按钮后,就会显示如下对话框样式的DatePickerDialog
当点击“设置时间”按钮后,就会弹出如下对话框样式的TimePickerDialog