import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
Date date1 = new Date(); // 这个就能获取当前的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 将Date类型转化成相应的字符串类型
String str = sdf.format(date1); // Date转换动作
Timestamp timestamp = Timestamp.valueOf(str); // str转换成Timestamp
System.out.println(date1);
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.Calendar;
// 获取 Date 类型
Date date = new GregorianCalendar(year, month, day).getTime(); // java8
// 获取 alendar 类型
Calendar c = Calendar.getInstance();
c.set(year, month - 1, day, 0, 0);
Date todayDate = new Date();
if(todayDate.after(historyDate) && todayDate.before(futureDate)) {
// In between
}
import java.util.Calendar;
int totalNumberOfWeeks = Calendar.getInstance().getActualMaximum(Calendar.WEEK_OF_YEAR);
import java.util.Calendar;
Calendar.getInstance().get(Calendar.YEAR); // 当前年份
Calendar.getInstance().get(Calendar.MONTH) + 1; // 当前月份 index 从 0 开始
Calendar.getInstance().get(Calendar.DAY_OF_MONTH); // 当前日期
Calendar.getInstance().get(Calendar.HOUR_OF_DAY); // 当前小时
import java.utils.Calendar;
import java.utils.GregorianCalendar;
Calendar calendar = new GregorianCalendar(2000, Calendar.FEBRUARY, 1));
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); // 29
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
sdf.format(date);