Calendar 类 set(int field, int value) 将给定的日历字段设置为给定值。 Calendar ca = Calendar.getInstance(); ca.set(ca.YEAR, year); ca.set(ca.MONDAY, month); ca.set(ca.DAY_OF_MONTH, day); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String dateStr = sdf.format(ca.getTime());
use calendar or SimpleDateFormat //Calendar Calendar c = Calendar.getInstance(); c.setTime(tempDate.parse(year)); int h = Integer.parseInt(hour).intValue(); int m = Integer.parseInt(minute).intValue(); c.set(Calendar.HOUR_OF_DAY, h); c.set(Calendar.MINUTE, m); Date d = c.getTime();//SimpleDateFormat SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String s = year + " " + hour + ":" + monite + ":00"; Date d = sf.parse(s);
直接用string然后转化就行了
因为我的那个时间和分钟是页码拿的参数,如何组合起来?组合成什么样子才能用MySql的转?
set(int field, int value)
将给定的日历字段设置为给定值。 Calendar ca = Calendar.getInstance();
ca.set(ca.YEAR, year);
ca.set(ca.MONDAY, month);
ca.set(ca.DAY_OF_MONTH, day);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(ca.getTime());
//Calendar
Calendar c = Calendar.getInstance();
c.setTime(tempDate.parse(year));
int h = Integer.parseInt(hour).intValue();
int m = Integer.parseInt(minute).intValue();
c.set(Calendar.HOUR_OF_DAY, h);
c.set(Calendar.MINUTE, m);
Date d = c.getTime();//SimpleDateFormat
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String s = year + " " + hour + ":" + monite + ":00";
Date d = sf.parse(s);