您的位置:首页 > 移动开发 > Android开发

android 格林尼治标准时间的 格式转换 (String To Date) 报错 java.text.ParseException: Unparseable date

2014-02-16 17:38 615 查看
首先 Mon Dec 09 22:06:24 格林尼治标准时间+0800 2013 字段一个格林尼治标准时间时间,一般情况下字段中不会含有中文,对于这种格式有两种解决方法

1剔除中文字符串

public static String convertGMTToLoacale(String gmt){

String cc = gmt.substring(0, 19) + gmt.substring(33, 38);

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy",new Locale("English"));

try {

Date date = sdf.parse(cc);

SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM");

String result = dateformat.format(date);

return result;

} catch (ParseException e) {

}

return "";

}

2.第二种方法是在不进行字符串剔除的情况下:

在simpleDateFormat方法中将格式字符串变换为:"EEE MMM dd HH:mm:ss 格林尼治标准时间+0800 yyyy" 就可以了。这样就可一将时间转换为Date类型:

private DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss 格林尼治标准时间+0800 yyyy",Locale.ENGLISH);

http://blog.csdn.net/kernel_32/article/details/17770943
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: