import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 日期格式解析
* User: yfzhangbin
* Date: 13-1-9
* Time: 下午6:06
*/
public class DateParse {
public static void main(String[] args) throws ParseException {
String d = "Wed Jan 02 15:03:55 CST 2013";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
Calendar calendar = Calendar.getInstance();
calendar.setTime(sdf.parse(d));
System.out.println("年" + calendar.get(Calendar.YEAR));
System.out.println("月" + (calendar.get(Calendar.MONTH) + 1));
System.out.println("日" + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("时" + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("分" + calendar.get(Calendar.MINUTE));
System.out.println("秒" + calendar.get(Calendar.SECOND));
System.out.println("周" + calendar.get(Calendar.DAY_OF_WEEK));
}
}
分享到:
2013-01-10 10:04
浏览 792
评论
1 楼
medicine
2013-01-10
js 解析也附上
var d = new Date(Date.parse("Wed Jan 02 15:03:55 CST 2013"));
var t = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
console.info(d);