[英]How to change date's format from milliseconds
I am receiving last modification date of a file, using below code: 我正在使用以下代码接收文件的最后修改日期:
xmlUrl = new URL("http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html");
URLConnection urlconn = xmlUrl.openConnection();
urlDate = new Date(urlconn.getLastModified());
In result I am getting date in below format: 结果,我得到以下格式的日期:
Tue Dec 18 05:11:33 Asia/Karachi 2007
I want to change it to simple dd MMM yyyy format 我想将其更改为简单的dd MMM yyyy格式
I used: 我用了:
SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
try {
tempDate = format.parse(urlDate.toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
but it didn't help me to solve the issue and I am still getting the date in that above mentioned long format. 但这并没有帮助我解决问题,而且我仍然能获得上述长格式的日期。
tempDate = format.parse(urlDate.toString());
That's backwards and should lead to an exception. 那是倒退,应该导致异常。 A
DateFormat
is for converting between String
and Date
both ways, and the format string must always match the pattern of the String
side. DateFormat
用于在String
和Date
之间进行双向转换,格式字符串必须始终与String
端的模式匹配。
What you want is this: 您想要的是:
tempDate = format.format(urlDate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.