请问怎样才能将一个Date对象的小时、分钟、秒去掉,得到一个只有日期的Date对象呢?

解决方案 »

  1.   

    顶者接分~~顺便为我的兼职工作宣传:
    如果你是经常上网的话,那不如挂个赚钱的广告条,那样就可以一边上网一边赚钱了。
    只要挂着一个小软件,无须经常手动就能赚钱,至少能把网费赚回来!(可全职,可兼职)
    1.先去注册一个帐号:
    通宝注册地址(登陆后全自动):
    http://www.8qu.net/register.asp?net=those8377
    新闻吧注册地址(十多分钟手动一次):
    http://www.ads4cn.com/newsbar/refferer.asp?those8377
    2.下载挂钱软件
    3.打开登陆
      

  2.   

    public static String format(Date date, String format) {
           if(date == null || format == null) {
                return null;
                    } else {
                SimpleDateFormat sdf = new SimpleDateFormat(format);
                return sdf.format(date);
                    }
                }
      

  3.   

    火焰神,你那个返回来的是String ,我要Date对象啊
      

  4.   


    java.util.Date dd=new java.util.Date();java.sql.Date d=java.sql.Date.valueOf(new java.sql.Date(dd.getTime()).toString());这样得到的就是只有日期的了。
      

  5.   

    pigo(p) 已经说出了答案。我来接分。
      

  6.   

    import java.awt.*;
    import javax.swing.*;
    import java.util.*;public class date extends JFrame
    {  
    String s;
    JPanel panel=new JPanel();
    JLabel lab=new JLabel(s);
    Date date=new Date();
        GregorianCalendar gc=new GregorianCalendar();       public date()
        {
         super("Date");
         this.getContentPane().add(panel);
         panel.add(lab);
         s=(gc.get(gc.MONTH)+1)+"/"+gc.get(gc.MINUTE)+"/"+gc.get(gc.YEAR);
         gc.setTime(date);
    lab.setText(s);
         this.setSize(200,200);
         this.setVisible(true);
        }
        
        public static void main(String args[])
        {
         new date();
        }
    }
      

  7.   

    以上代码有一点小错误
    修正版:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;public class date extends JFrame
    {  
        String x;
        JPanel panel=new JPanel();
        JLabel lab=new JLabel(x);
        Date date=new Date();
        GregorianCalendar gc=new GregorianCalendar();    public date()
        {
         super("Date");
         this.getContentPane().add(panel);
         panel.add(lab);
        
         x=(gc.get(gc.MONTH)+1)+"/"+gc.get(gc.DATE)+"/"+gc.get(gc.YEAR);
         gc.setTime(date);
    lab.setText(x);

    this.setDefaultCloseOperation(3);
    this.setResizable(false);
         this.setSize(200,200);
         this.setVisible(true);
        }
        
        public static void main(String args[])
        {
         new date();
        }
    }
      

  8.   

    SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
        Date now = new Date();
        String logEntry = formatter.format(now);
        Date today = null;
        try {
           today = formatter.parse(logEntry);
        } catch ( ParseException exc ) {
           exc.printStackTrace();
        }
      

  9.   

    if (rs.getString(6)!=null){
    uBean.setDate(repNull(rs.getString(6)).substring(0,10));
    }else{
    uBean.setDate(repNull(rs.getString(6)));
    }
      

  10.   

    刚发错了。
    只用下面的话就行了:
    Date dt;
    dt.substring(0,10));
      

  11.   

    public static String getSystemtime(){
       int yyyy,mm,dd;
       String Systemtime = null;
       Calendar c=Calendar.getInstance(); 
       yyyy=c.get(Calendar.YEAR); 
       mm=c.get(Calendar.MONTH) +1; 
       dd=c.get(Calendar.DAY_OF_MONTH);
       if(mm<10){
       if(dd<10){
       Systemtime =  yyyy+"-0"+mm+"-0"+dd;
       }else{
       Systemtime =  yyyy+"-0"+mm+"-"+dd;
       }
       }else{
       if(dd<10){
       Systemtime =  yyyy+"-"+mm+"-0"+dd;
       }else{
       Systemtime =  yyyy+"-"+mm+"-"+dd;
       }
       }
       return Systemtime;
       }
      

  12.   

    你为什么只要日期呢?只需要在取的时候只取年月日不就行了吗?(内存中的还是完整的日期时间)另外象“oldbig615”那样使用df.parser()好象是个不错的办法!
      

  13.   

    Date date=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    String time=sdf.format(date);
    date=java.sql.Date.valueOf(time);