【问题标题】:Getting the Date format in Java [duplicate]在Java中获取日期格式[重复]
【发布时间】:2013-03-10 21:38:47
【问题描述】:

我有这个来自Date 对象的StringMon Mar 25 00:00:00 IST 2013

String 表示的日期格式是什么?

【问题讨论】:

标签: java date simpledateformat


【解决方案1】:

下面的代码应该可以正常工作。

public static void main(String[] args) throws Exception {
    String target = "Mon Mar 25 00:00:00 IST 2013";
    DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);
    Date result =  df.parse(target);  
    System.out.println(result);
}

阅读javadoc 了解有效模式。

【讨论】:

    【解决方案2】:
    String yourDate= "Mon Mar 25 00:00:00 IST 2013" ;
    DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    Date jDate = new Date(df.parse(yourDate).getTime());
    System.out.println(jDate);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多