【问题标题】:Java date pattern [duplicate]Java日期模式[重复]
【发布时间】:2015-04-20 15:41:48
【问题描述】:

我有这个字符串输出'Wed Apr 01 09:50:31 CEST 2015' 谁能告诉我那是什么模式。我需要它才能在另一个功能中使用它。

@Test
public void test() throws ParseException {
    String input = "Wed Apr 01 09:50:31 CEST 2015";
    String format = "DD MM hh:mm:ss YYYY"; // i have a wrong format

    SimpleDateFormat df = new SimpleDateFormat(format);
    Date date = df.parse(input);

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int week = cal.get(Calendar.WEEK_OF_YEAR);
    System.out.println(week);
}

在我的情况下找出正确的日期模式格式的任何帮助。

【问题讨论】:

标签: java


【解决方案1】:

您的问题的解决方案是使用

覆盖默认日期区域设置
SimpleDateFormat(String pattern, Locale locale) constructor:

DateFormat dateFormat = new SimpleDateFormat(
        "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
dateFormat.parse("Tue Jul 13 00:00:00 CEST 2011");
 System.out.println(dateFormat.format(new Date()));

How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)的解决方案副本

【讨论】:

  • 加一个不要忘记定义Locale
猜你喜欢
  • 2019-12-09
  • 1970-01-01
  • 1970-01-01
  • 2019-01-17
  • 1970-01-01
  • 2016-09-23
  • 1970-01-01
  • 2013-03-31
  • 2023-03-27
相关资源
最近更新 更多