java.util.Date now = new java.util.Date();
       SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String date=df.format(now);

解决方案 »

  1.   

    Data转换成String:
    public String toString() {
              SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
              StringBuffer tb = new StringBuffer();
              return sdf.format(this, tb, new FieldPosition(0)).toString();      }
    String转换成Data:
    public static String getDateOutput(String outputDate) {
              String outDate = "";
              if (outputDate == null)
                  return outDate;
              if (outputDate.length() == 8 || outputDate.length() == 14) {
                  String year = outputDate.substring(0, 4);
                  String month = outputDate.substring(4, 6);
                  String day = outputDate.substring(6, 8);
                  outDate = year + "-" + month + "-" + day;
                  if (outputDate.length() > 8) {
                      String hour = outputDate.substring(8, 10);
                      String minute = outputDate.substring(10, 12);
                      String second = outputDate.substring(12, 14);
                      outDate += " " + hour + ":" + minute + ":" + second;
                  }
              }
              return outDate;
          }
      

  2.   

    Data转换成String:
    public String toString() {
              SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
              StringBuffer tb = new StringBuffer();
              return sdf.format(this, tb, new FieldPosition(0)).toString();      }
    String转换成Data:
    public static String getDateOutput(String outputDate) {
              String outDate = "";
              if (outputDate == null)
                  return outDate;
              if (outputDate.length() == 8 || outputDate.length() == 14) {
                  String year = outputDate.substring(0, 4);
                  String month = outputDate.substring(4, 6);
                  String day = outputDate.substring(6, 8);
                  outDate = year + "-" + month + "-" + day;
                  if (outputDate.length() > 8) {
                      String hour = outputDate.substring(8, 10);
                      String minute = outputDate.substring(10, 12);
                      String second = outputDate.substring(12, 14);
                      outDate += " " + hour + ":" + minute + ":" + second;
                  }
              }
              return outDate;
          }
      

  3.   

    String 到 Date:
    String strDate="2003-06-30";
    java.sql.Date dt=java.sql.Date.valueOf(strDate);
      

  4.   

    使用java.text.DateFormat或者java.text.SimpleDateFormat