SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd");
//年月日
String year=tempDate.format(new Date());
// 时
String hours = "12";
// 分
String minute = "30";
现在有String类型的年月日,时和分,如何把它组合成Data类型的格式?因为我要录入到数据库里面去,而且是MySql的数据库!请各位大大帮忙....

解决方案 »

  1.   

    mysql不是有date_format函数么
    直接用string然后转化就行了
      

  2.   


    因为我的那个时间和分钟是页码拿的参数,如何组合起来?组合成什么样子才能用MySql的转?
      

  3.   

    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());
      

  4.   

    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);
      

  5.   

    办公室空调开高了,头都晕了理解错了,不过用Calendar类,可以设置你要的时间,就用set(field,value)给不同的字段赋值就可以了