形如Mon Dec 31 00:00:00 CST 2012字符串转换为相应日期Date

package com.tender.news.util;

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) {
        String str = "Mon Dec 31 00:00:00 CST 2012";
//        Date now=new Date();
        Date date = parse(str, "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
//        String str2=format(now, "EEE MMM dd HH:mm:ss zzz yyyy", Locale.CHINA);
        System.out.printf("%tF %//        System.out.println(str2);
    }
//形如Mon Dec 31 00:00:00 CST 2012字符串转换为相应日期Date
    public static Date parse(String str, String pattern, Locale locale) {
        if(str == null || pattern == null) {
            return null;
        }
        try {
            return new SimpleDateFormat(pattern, locale).parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
//
    public static String format(Date date, String pattern, Locale locale) {
        if(date == null || pattern == null) {
            return null;
        }
        return new SimpleDateFormat(pattern, locale).format(date);
    }
}

你可能感兴趣的:(形如Mon Dec 31 00:00:00 CST 2012字符串转换为相应日期Date)