日期:2014-05-20  浏览次数:20745 次

请教一个关系时间日期格式的转换格式化的问题~~!!谢谢了!
我传入一个   String型的   日期格式:   "yyyy-mm-dd "           例如: "2007-03-16 "  
然后我希望将其转换为   "yyyy-mm-dd   08:00:00 "                 如: "2007-03-16   08:00:00 "  
并且计算出他前一天的日期,格式也是 "yyyy-mm-dd   08:00:00 "     如: "2007-03-15   08:00:00 "

请大家指点指点,谢谢了!

------解决方案--------------------

Date d = new SimpleDateFormat( "yyyy-MM-dd ").parse( "2007-03-16 ");// 2007-03-16
// 08:00:00
System.out.println(new SimpleDateFormat( "yyyy-MM-dd 08:00:00 ")
.format(d));
Date yesterday = new Date(d.getTime() - 1000L * 3600L * 24);
System.out.println(new SimpleDateFormat( "yyyy-MM-dd 08:00:00 ")
.format(yesterday));


------解决方案--------------------
public class test_11 {

/**
* @param args
*/
public static void main(String[] args) {

String s = "2007-03-16 ";
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd ");
try {
Date date=sdf.parse(s);
SimpleDateFormat sdf1=new SimpleDateFormat( "yyy-MM-dd 08:00:00 ");
System.out.println(sdf1.format(date));
Long l=date.getTime();
Long l_1=l-24*60*60*1000L;
System.out.println(sdf1.format(l_1));
} catch (ParseException e) {
e.printStackTrace();
}

}

}
结果:
07-03-16 08:00:00
07-03-15 08:00:00