请问怎样才能将一个Date对象的小时、分钟、秒去掉,得到一个只有日期的Date对象呢?
解决方案 »
- Exception in thread "main" java.lang.NoClassDefFoundError:(大家帮我看看这个程序。。。)
- 基础问题
- 文件合并写入问题~~求助
- 类加载和初始化顺序,多谢帮忙看看
- HashSet的一个问题!
- java中怎样得到SQL Server 2000 存储过程的结果集
- 如何做到让applet只初始化一次!
- ☆★☆★substring不执行问题,执行完substring上一行就退出函数了☆★☆★
- javax.swing.SwingWorker类的一个问题
- 请给初学Java的Freshman一个建议!
- 求不同格式的日期字符串转换成日期的通用解决方案
- Java的网络高手和Xml高手请进(三)
如果你是经常上网的话,那不如挂个赚钱的广告条,那样就可以一边上网一边赚钱了。
只要挂着一个小软件,无须经常手动就能赚钱,至少能把网费赚回来!(可全职,可兼职)
1.先去注册一个帐号:
通宝注册地址(登陆后全自动):
http://www.8qu.net/register.asp?net=those8377
新闻吧注册地址(十多分钟手动一次):
http://www.ads4cn.com/newsbar/refferer.asp?those8377
2.下载挂钱软件
3.打开登陆
if(date == null || format == null) {
return null;
} else {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
}
java.util.Date dd=new java.util.Date();java.sql.Date d=java.sql.Date.valueOf(new java.sql.Date(dd.getTime()).toString());这样得到的就是只有日期的了。
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();
}
}
修正版:
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();
}
}
Date now = new Date();
String logEntry = formatter.format(now);
Date today = null;
try {
today = formatter.parse(logEntry);
} catch ( ParseException exc ) {
exc.printStackTrace();
}
uBean.setDate(repNull(rs.getString(6)).substring(0,10));
}else{
uBean.setDate(repNull(rs.getString(6)));
}
只用下面的话就行了:
Date dt;
dt.substring(0,10));
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;
}
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String time=sdf.format(date);
date=java.sql.Date.valueOf(time);