【问题标题】:Time stamp of date and time both in java [closed]java中日期和时间的时间戳[关闭]
【发布时间】:2012-10-31 12:52:57
【问题描述】:

如何根据格式找到日期和时间的时间戳:

Wed Oct 31 17:40:42 IST 2012

【问题讨论】:

标签: java android timestamp


【解决方案1】:

使用SimpleDateFormat 解析您的日期

SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(parserSDF.format(cal.getTime()));

它将打印为Wed Oct 31 18:28:55 IST 2012

【讨论】:

    【解决方案2】:

    使用SimpleDateFormat:

    String str_date = "Wed Oct 31 18:28:55 IST 2012";
    
    // Here is your date as string
    
    DateFormat formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
    Date date = (Date) formatter.parse(str_date); 
    Timestamp timeStampDate = new Timestamp(date.getTime());
    
    // Here is your date as timestamp
    

    【讨论】:

      猜你喜欢
      • 2013-11-03
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      相关资源
      最近更新 更多