本帖最后由 zhaoyang0619 于 2009-08-27 14:27:43 编辑

解决方案 »

  1.   

    java.text.SimpleDateFormat这个可以实现
      

  2.   

    SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd");   
            String a=dateformat.format(new Date());
            System.out.println(a); 
      

  3.   

    SimpleDateFormat dateformat=new SimpleDateFormat("yyyy年-MM月-dd日");
             String a=dateformat.format(new Date());
             System.out.println(a);
      

  4.   

    SimpleDateFormat要什么样的就能转什么样的。。
      

  5.   

    sqlserver MS是自动转的,直接string就转成(数据库的)date了,直接就可以between  and 
      

  6.   


    import java.util.*;
    import java.text.SimpleDateFormat;public class TestSimpleDateForma {
    public static void main(String[] args) {        Calendar cal =Calendar.getInstance();
            cal.set(2009,5,1);
            
            //需要转换的格式
            SimpleDateFormat now = new SimpleDateFormat("yyyy年MM月dd日");
            //打印结果
            System.out.println(now.format(cal.getTime()));
            //2009年06月05日,注意:cal.set(2009,5,1);
    }
    }
      

  7.   

    String sd=request.getParameter("sdate");
    String ed=request.getParameter("edate");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      Date sdate = new Date();
      Date edate = new Date();
      try {
       sdate = sdf.parse(sd);
       edate = sdf.parse(ed);
      }catch (java.text.ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
      System.out.println(sdate);
      System.out.println(edate);这是我以前写的,可是输入来的不是我想 要的格式呀
      

  8.   

    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateFormat { public static void main(String[] args) {
    // TODO Auto-generated method stub
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年-MM月-dd日");
    String formatDate= sdf.format(date);
    System.out.println("时间格式:"+formatDate);
                    //时间格式:2009年-08月-27日
    }}请参考
      

  9.   

    输出结果为Tue Aug 25 00:00:00 CST 2009
      

  10.   

    对于yyyy-mm-dd的字符串,一般数据库会自动转的,不必转为Date类型
    一个日期类型不会print出为yyyy-mm-dd这种格式
      

  11.   

    date格式必须format才能变成你想要的格式
      

  12.   

    那我要怎么做才能达到我的目的
    select * from table where fdate between 起始日期 and 终止日期 
      

  13.   

    String sd=request.getParameter("sdate"); 
    String ed=request.getParameter("edate"); 
    那我直接
    select * from table where fdate between sd and ed   ????
      

  14.   

    这样做完全可以
    id1为你接收的起始时间
    id2为你的接收的结止时间String sql="select * from table  where date between '" + id1 + "' and '" + id2 + "' order by date"
      

  15.   

    假如后面还要跟条件 and 就好!!
      

  16.   


    在SQL SERVER里这样写没问题在Oracle里需要这样转换一下
    BETWEEN TO_DATE('2009-08-01', 'YYYY-MM-DD') AND TO_DATE('2009-08-10', 'YYYY-MM-DD')
      

  17.   

    可是他表里面的fdate是datetime类型的
    我这样写之后查不出数据,都是空的
      

  18.   

    那你里写错了吗?
    我的数据库的也是个数据类型datetime
    还测试了
      

  19.   


    String sql="select * from table  where fdate between '" + fd + "' and '" + ed + "' order by date"String sd=request.getParameter("sdate").trim(); 
    String ed=request.getParameter("edate").trim(); 
      

  20.   

    DateFormat中的方法比较:
    format(Date date)将一个 Date 格式化为日期/时间字符串;
    parse(String source)从给定字符串的开始解析文本,以生成一个日期。
    在这你可以使用format方法格式化成你自己想要的格式。