import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateTime {
public static void main(String[] args) throws Exception{//时间格式转换
String s1 = "09-Dec-2011 12:00:00";
Date time = new Date();
SimpleDateFormat sdf =
new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US);
time = sdf.parse(s1);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
s1 = sdf2.format(time);
System.out.println(s1);
//获取当前系统时间
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowtime= sdf1.format( new Date());
System.out.println(nowtime);
//时间格式转换、
String s2 = "10/30/2012";
SimpleDateFormat sdf3 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf4.format(sdf3.parse(s2)));
}
}
运行结果: