EEE,dd MMM yyyy HH:mm:ssZ的日期格式是什么? [英] What is date format of EEE, dd MMM yyyy HH:mm:ssZ?

查看:374
本文介绍了EEE,dd MMM yyyy HH:mm:ssZ的日期格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android上对此进行解析:

I'm trying to parse this on Android:

Fri, 02 Oct 2015 10:01:00+0300

格式为 EEE,dd MMM yyyy HH:mm:ssZ ,但不起作用。

item_date = "Fri, 02 Oct 2015 18:07:00+0300";
SimpleDateFormat curFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssZ");

Date dateObj = null;
String newDateStr = item_date;
try {
  dateObj = curFormater.parse(item_date);
} catch (ParseException e) {
  e.printStackTrace();
}


推荐答案

为了解析字符串放入包含某些单词(例如该月份)的 Date 中,则需要相应于该语言的相应的 Locale 这些话。因为在您的示例中它们是英语,所以您可以使用特定于语言的语言环境,例如 java.util.Locale.ENGLISH 或特定国家/地区的语言环境,例如 java .util.Locale.US Locale.UK

In order to parse a String into a Date which contains certains words (e.g. for the month), then you need an appropriate Locale corresponding to the language of these words. Since they are in english in your example you could use a language specific locale like java.util.Locale.ENGLISH or a country specific one, like java.util.Locale.US or Locale.UK.

因为您可以通过 Locale SimpleDateFormat 构造函数,您的实例化可能像这样:

Since you can pass the Locale to the SimpleDateFormat constructor your instantiation could look like this:

SimpleDateFormat curFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssZ", Locale.ENGLISH);

如果您想知道当前使用的 Locale中允许的日期格式字词,那么您可以尝试以下代码段,该代码段使用 DateFormatSymbols 类:

If you like to know the allowed date format words in your currently used Locale, then you can try the following snippet, which uses the DateFormatSymbols class:

DateFormatSymbols dfs = new DateFormatSymbols();
System.out.println(Arrays.toString(dfs.getShortMonths()));

此类提供相应的方法来获取月份,缩写月份或工作日。

您还可以将 Locale 传递给 DateFormatSymbols 构造函数,以从特定语言环境获取这些字符串。

This class provides corresponding methods to get months, the abbreviated months or the weekdays.
You can also pass a Locale to the DateFormatSymbols constructor to get these strings from the specific locale.

这篇关于EEE,dd MMM yyyy HH:mm:ssZ的日期格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆