Strng sourceDate="2002-8-10"
SimpleDateFormat df=new SimpleDateFormat("yyyyMMdd");
String sqldate=df.format(sourceDate);

解决方案 »

  1.   

    Strng sourceDate="2002-8-10"
    java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyyMMdd");
    String sqldate=df.format(sourceDate);
      

  2.   

    String dt = "2002-11-8"
    String str = dt.toString()
    str = str.replace("-","")
      

  3.   

    2002-8-10也是字符串格式呀!!
    SimpleDateFormat 变量=new SimpleDateFormat(格式字符串)
    SimpleDateFormat 变量.format(Date 数据)
      

  4.   

    提示如下错误:
    D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\_\Title$jsp.java:82: Class org.apache.jsp.SimpleDateFormat not found.
                    SimpleDateFormat  df=new  SimpleDateFormat("yyyy年mm月dd");  
      

  5.   

    还是有问题,提示错误:
    Cannot format given Object as a Date程序源码:
    <%@ page contentType="text/html;charset=gb2312"%> 
    <%@ page import="java.util.*" %>
    <%
    //变量声明 
    java.sql.Connection  sqlCon;  //数据库连接对象 
    java.sql.Statement  sqlStmt;  //SQL语句对象 
    java.sql.ResultSet  sqlRst;  //结果集对象 
    java.lang.String  strCon;  //数据库连接字符串 
    java.lang.String  strSQL;  //SQL语句
    java.lang.String  strHospitalname; //工作组的号
    String  strServerDate; //当前工作组的号 
    String  strCurrentDate; //当前工作组的号
    //装载JDBC-ODBC驱动程序 
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    //设置数据库连接字符串 
    strCon = "jdbc:odbc:web"; 
    //连接数据库 
    sqlCon = java.sql.DriverManager.getConnection(strCon,"ttba","ttba"); 
    //创建SQL语句对象 
    sqlStmt = sqlCon.createStatement(); 
    //得到树型信息 
    strSQL = "select hospitalname,sysDate from wq_web_server_def" ; 
    sqlRst = sqlStmt.executeQuery(strSQL); 
    sqlRst.next();
    strHospitalname = sqlRst.getString(1);
    strServerDate = sqlRst.getString(2);
    java.text.SimpleDateFormat  df=new  java.text.SimpleDateFormat("yyyyMMdd");  
    strServerDate = "2002-8-10";
    strCurrentDate = strServerDate;
    //strCurrentDate = df.format(strServerDate); 
    %>
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    <base target="contents">
    </head><body topmargin="0" leftmargin="0"><div align="left">
      <table border="0" cellspacing="0" cellpadding="0" style="padding-left: 0" width="796" height="70">
        <tr>
          <td width="792" height="70" background="Image/TitleMain.jpg">
            <div align="center">
              <center>
              <table border="0" width="350" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="100%">
                    <p align="center"><b><font color="#FFFFFF" face="楷体_GB2312" size="6"><%=strHospitalname%></font></b></td>
                </tr>
              </table>
              </center>
            </div>
          </td>
          <td width="70" height="70">
    <applet code="billsClock.class" width="70" height="70" align="MIDDLE">
              <param name="BGCOLOR" value="FFFFFF">
              <param name="FACECOLOR" value="FFFFFF">
              <param name="SWEEPCOLOR" value="FF0000">
              <param name="MINUTECOLOR" value="008080">
              <param name="HOURCOLOR" value="000080">
              <param name="TEXTCOLOR" value="000000">
              <param name="CASECOLOR" value="000080">
              <param name="TRIMCOLOR" value="C0C0C0">
              <param name="LOGOIMAGEURL" value="java.gif">
              <param name="LOCALONLY" value="1">
            </applet>      
          </td>
        </tr>
      </table>
    </div><table border="0" width="100%" cellspacing="0" cellpadding="0" height="16">
      <tr>
        <th width="177" bgcolor="#6B8AB8" height="16" nowrap>
          <p align="center"><font face="宋体" size="2" color="#FFFFFF"><b>管理树</b></font></th>
        <th width="100%" bgcolor="#003399" height="16" nowrap>
          <p align="left"><font face="宋体" size="2"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          <font color="#FFFFFF">欢迎你:苗森&nbsp;&nbsp;   
          所属科室:眼科&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
          <%=strCurrentDate%></font></b></font> </th> 
      </tr> 
    </table> 
     
    </body> 
     
    </html> 
    <%
         sqlRst.close(); //结果集对象 
         sqlStmt.close(); //SQL语句对象 
         sqlCon.close();; //数据库连接对象 
    %>