本文整理汇总了Java中android.widget.DatePicker.getYear方法的典型用法代码示例。如果您正苦于以下问题:Java DatePicker.getYear方法的具体用法?Java DatePicker.getYear怎么用?Java DatePicker.getYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.DatePicker
的用法示例。
在下文中一共展示了DatePicker.getYear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.DatePicker; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_date);
datePicker = (DatePicker) findViewById(R.id.datePicker);
date = datePicker.getDayOfMonth();
month = datePicker.getMonth() +1 ;
year = datePicker.getYear();
Log.d("date",date+" "+month+" "+year);
next = (Button) findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
date = datePicker.getDayOfMonth();
month = datePicker.getMonth() + 1;
year = datePicker.getYear();
Log.d("date",date+" "+month+" "+year);
Intent i = new Intent(getApplicationContext(),Message.class);
startActivity(i);
}
});
}
示例2: onDateSet
import android.widget.DatePicker; //导入方法依赖的package包/类
public void onDateSet(DatePicker view, int year, int month, int day) {
TextView dateView= (TextView) getActivity().findViewById(R.id.textTo);
String dateToDisplay=view.getYear()+"-"+String.format("%02d", view.getMonth()+1)+"-"+String.format("%02d",view.getDayOfMonth());
dateView.setText("Access valid to: "+dateToDisplay);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date mDate = sdf.parse(dateToDisplay);
long timeInSeconds = mDate.getTime()/1000;
Log.d("Share", "Date in milli : " + timeInSeconds);
((ShareActivity)getActivity()).setDateTo(timeInSeconds);
} catch (ParseException e)
{
e.printStackTrace();
}
}
示例3: getDateFromDatePicker
import android.widget.DatePicker; //导入方法依赖的package包/类
public static Calendar getDateFromDatePicker(DatePicker datePicker){
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth();
int year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
return calendar;
}