[英]Android: How to convert string into date
I am currently working on a calendar application using Caldroid and the date that Caldroid returns looks like this: 我目前正在使用Caldroid开发日历应用程序,而Caldroid返回的日期如下所示:
Fri Jun 17 12:31:00 GMT+07:00 2016
I just need to extract the date from it like for example: 我只需要从中提取日期,例如:
17-06-2016
How am I supposed to do that? 我应该怎么做?
Try this - 尝试这个 -
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");
try {
//This will give you the desired output
df2.format(df.parse("Fri Jun 17 12:31:00 GMT+07:00 2016"));
} catch (ParseException e) {
e.printStackTrace();
}
You can use SimpleDateFormat. 您可以使用SimpleDateFormat。 Please refer to the address http://tutorials.jenkov.com/java-internationalization/simpledateformat.html
请参考地址http://tutorials.jenkov.com/java-internationalization/simpledateformat.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.