java 如何将“Thu Aug 04 00:00:00 IST 2011”解析为“04-08-2011”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6952758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to parse "Thu Aug 04 00:00:00 IST 2011" to "04-08-2011"?
提问by n92
I want to parse the date Thu Aug 04 00:00:00 IST 2011
to dd-MM-YY
format like 04-08-2011
. How to do this in Java?
我想分析的日期Thu Aug 04 00:00:00 IST 2011
,以dd-MM-YY
类似格式04-08-2011
。如何在 Java 中做到这一点?
回答by Bozho
Use the following format to parse: EEE MMM dd HH:mm:ss z yyyy
with SimpleDateFormat.parse(..)
使用以下格式解析:EEE MMM dd HH:mm:ss z yyyy
withSimpleDateFormat.parse(..)
The use another SimpleDateFormat
with the dd-MM-yy
format, to format(..)
the resultant date. Something like:
在使用其他SimpleDateFormat
与dd-MM-yy
格式,向format(..)
得到的日期。就像是:
SimpleDateFormat parseFormat =
new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Date date = parseFormat.parse(dateString);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yy");
String result = format.format(date);
回答by Thennisha
I hope you can find the solution from the sample code below
我希望你能从下面的示例代码中找到解决方案
import java.text.DateFormat;
import java.util.Date;
public class DateFormatExample
{
public static void main(String args[])
{
Date now=new Date();
System.out.println("dd/mm/yy format:" +DateFormat.getDateInstance(DateFormat.SHORT).format(now));
}
}
Now you will get your required format....
现在您将获得所需的格式....