public class MainActivity extends AppCompatActivity { private TimePicker timePicker; private DatePicker datePicker; private Calendar cal; private int year; private int month; private int day; private int hour; private int minute; @Override protected
1.Date对象:Date date = getDate(); 2.Calendar实例:Calendar calendar = Calendar.getInstance(); 3.calendar.setTime(date); 4.int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); 参考网址
抄的人家的,仅作学习使用. java Date获取 年月日时分秒 package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; public class Test { public void getTimeByDate(){ Date date = new Date(); DateFormat df1 =
date 表示年月日,如YY-MM-DD datetime 表示年月日和时间信息,如YY-MM-DD HH:MM:SS datestamp 和datetime表示的信息相同,但时间范围不同 时间范围 date -- > '1000-01-01' to '9999-12-31'. datetime --> '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. datestamp -- > '1970-01-01 00:00:01' UTC to '