Date da=new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(sdf.format(da));
测试代码: Date d = new Date(); System.out.println(d); SimpleDateFormat sdf = new SimpleDateFormat(); System.out.println( sdf.format(d));测试结果: Tue Nov 08 13:26:37 CST 2005 05/11/08 13:26
先df.parse();然后 df.format();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(da));
Date d = new Date();
System.out.println(d); SimpleDateFormat sdf = new SimpleDateFormat();
System.out.println( sdf.format(d));测试结果:
Tue Nov 08 13:26:37 CST 2005
05/11/08 13:26
String str="Nov 8, 2005 11:33:15 AM";
DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
String result=df.format(new Date());
System.out.println(style.format( df.parse(str)));
DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
String result=df.format(new Date());
System.out.println(style.format( df.parse(str)));把AM写为PM看看 !!
DateFormat style = new SimpleDateFormat("yyyy-MM-dd k:mm:ss",
{
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat df = new SimpleDateFormat(toFormat);
df.setTimeZone(gc.getTimeZone());
String toDateString = df.format(date);
return toDateString;
}