import java.text.SimpleDateFormat;
import java.util.Date;
public class SimpleDateFormatObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date = new Date();
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(simpledateformat.format(date));
}
}
package com.zeph.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class Test {
public static void main(String[] args) throws ParseException {
String Time = "Wed, 12 Oct 2011 17:46:04 +0800";
String Time2 = "2011-10-12 16:44:19";
Date date = new Date();
SimpleDateFormat simpledateformat = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-mm-dd HH:mm:ss");
System.out.println(simpledateformat.format(date));
System.out.println(simpledateformat.parse(Time).toLocaleString());
System.out.println(dateFormat.parse(Time2).toLocaleString());
}
}
SimpleDateFormat使用
