日期:2014-05-18 浏览次数:20852 次
package com.yq.test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestDate {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String DateStr1 = "2011-10-1 10:20:16";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date dateTime1;
try {
dateTime1 = dateFormat.parse(DateStr1);
System.out.println("dateTime1=**************"+dateTime1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String DateStr1 = "2011-10-1 10:20:16";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date dateTime1;
String dateTime2;
try {
dateTime1 = dateFormat.parse(DateStr1);
dateTime2 = dateFormat.format(dateTime1); //format方法进行格式化
System.out.println("dateTime1=**************"+dateTime1);
System.out.println("dateTime2=**************"+dateTime2);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}