Generally Date is used for calculation,and String is used for display. Since you can get the real Date object, you will have everything including time and date. If you want to display it with a particular format, you have to format it again to be a String. For example:java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd"); java.util.Date theDate = fmt.parse("20041221");fmt.applyPattern("yyyy-MM-dd"); String desiredFormat = fmt.format(theDate);you will get the desiredFormat with value "2004-12-21";
不懂才问的啊,教我怎么查啊,我按照方法,返回的的确是"Tue Dec 21 00:00:00 GMT+08:00 2004",究竟哪里不对?
我只要"20041221"Date型的,该怎么做啊?
继续请教!
都告诉你 用 SimpleDateFormat 了.你自己查api,不就什么都知道了???
Since you can get the real Date object, you will have everything including
time and date. If you want to display it with a particular format, you have to format it again to be a String. For example:java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
java.util.Date theDate = fmt.parse("20041221");fmt.applyPattern("yyyy-MM-dd");
String desiredFormat = fmt.format(theDate);you will get the desiredFormat with value "2004-12-21";
你不可能去改变Date类的toString行为
如果要让Date显示为“20041221”,就应该再用SimpleDateFormat的format方法
yyyyMMddHHmmss
yyyy四位表示的年,如:1999
MM表示月,如:12
dd表示日期,如12号
HH表示24小时年,如16
mm表示分钟,如12
ss表示秒,如12秒