简体   繁体   English

将 adb shell 日期返回值转换为 Java 中的日期对象

[英]Converting adb shell date returned value to Date Object in Java

adb shell date returned Tue Feb 14 22:32:02 IST 2017 adb shell 日期返回 2 月 14 日星期二 22:32:02 IST 2017

I am trying to converting the "Tue Feb 14 22:32:02 IST 2017" to Date object in java.我正在尝试将“Tue Feb 14 22:32:02 IST 2017”转换为 Java 中的 Date 对象。 Can you please help in giving the sample snippet in Java to do the same.您能否帮忙提供 Java 中的示例代码段来做同样的事情。 I tried with SimpleDateFormat to parse this string, but somehow getting parse exception.我尝试使用 SimpleDateFormat 来解析这个字符串,但不知何故解析异常。

SimpleDateFormat formatter=new SimpleDateFormat("E, MMM dd yyyy HH:mm:ss");  
Date d = formatter.parse(dateStart);

The formatting pattern must match the data.格式模式必须与数据匹配。 Yours is not a match.你的不是比赛。

  • Remove the comma from your formatting pattern.从格式模式中删除逗号。 Your data has no comma.您的数据没有逗号。
  • Move the year symbol to the correct location.将年份符号移动到正确的位置。
  • Add a time zone symbol for the IST .IST添加时区符号。

Please search Stack Overflow before posting.发帖前请先搜索 Stack Overflow。 There are hundreds of examples you could have drawn from to solve your problem.您可以借鉴数百个示例来解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM