a为TIME OBJECT用 a.toString() 就可以返回 JDBC time 格式或者把日期分别取出来String timeString=new String(a.getYear()+"-"+a.getMonth()+"-"+a.getDay())
解决方案 »
- 窗体绘图问题
- 关于sun.security.action.GetPropertyAction的问题
- 回复"一著名软件公司的java笔试算法题"有兴趣请进
- 来看看透明窗体制作????
- 如何实现类似Dreamweaver的编辑HTML界面
- 为什么写不进去?请各位指教
- Applet打开网页的问题?
- [IBM][JDBC Driver] CLI0620E IOException, error reading from input stream. SQLSTATE=428A1
- 调查一下,现在有多少人用 Together ControlCenter ?
- 关于符点型数据问题
- 哭了,,谁帮我阿~100分立即给~~
- swing高手帮帮忙
import java.util.*; Date date = new Date();
new SimpleDateFormat("yyyy-MM-dd").format(date);
java.util.Date curDate = new java.util.Date();
String strDate = fmtDate.format (curDate);
import java.text.*;
import java.util.*; Date date = new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
format.format(date);就可以了.
* @author udate <a href="mailto:[email protected]">zgmg</a>
* @version 1.0
* @create time 2004-8-12
**/
public int compare(String formatStr,String a,String b){
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
//("hh:mm:ss");//时分秒
Date o1 = null;
Date o2 = null;
long n1 = 0l,n2 =0l;
try {
o1 = sdf.parse(a);
o2 = sdf.parse(b);
} catch (ParseException e) {
e.printStackTrace();
}
if(o1 != null){
n1 = o1.getTime();
}
if(o2 != null){
n2 = o2.getTime();
}
if (n1 < n2) {
return -1;
} else if (n1 > n2) {
return 1;
} else {
return 0;
}
}
GregorianCalendar currTime=new GregorianCalendar();
cuTime=currTime.get(currTime.YEAR)+"-"+currTime.get(currTime.MONTH)+"-"+currTime.get(currTime.DATE);
import java.util.Date;
然后在程序里
Date now=new Date();
SimpleDataFormat sdf=new SimpleDataFormat("yyyy-MM-dd");
String newDate=sdf.format(now);
newDate就是2004-08-16
因为在JAVA中0表示一月。改进后的方法为:
GregorianCalendar currTime=new GregorianCalendar();
cuTime=currTime.get(currTime.YEAR)+"-"+currTime.get(currTime.MONTH)+"-"+currTime.get(currTime.DATE);heibai520(Crazy Java)兄 看如何?