当前位置: 技术问答>java相关
File类的getLastModify()得到的是长型整数,如何才能得到一个已知文件日期?
来源: 互联网 发布时间:2015-01-25
本文导语: | private String getDate(File file) { String pattern=""; Calendar now=Calendar.getInstance(); Date fileDate=new Date(file.lastModified()); if(fileDate.before(now.getTime())) pattern="MM/dd/yyyy hh:mm a"; else pattern="EEEE hh:mm a";...
|
private String getDate(File file)
{
String pattern="";
Calendar now=Calendar.getInstance();
Date fileDate=new Date(file.lastModified());
if(fileDate.before(now.getTime()))
pattern="MM/dd/yyyy hh:mm a";
else
pattern="EEEE hh:mm a";
SimpleDateFormat formatter=new SimpleDateFormat(pattern);
return formatter.format(fileDate);
}
{
String pattern="";
Calendar now=Calendar.getInstance();
Date fileDate=new Date(file.lastModified());
if(fileDate.before(now.getTime()))
pattern="MM/dd/yyyy hh:mm a";
else
pattern="EEEE hh:mm a";
SimpleDateFormat formatter=new SimpleDateFormat(pattern);
return formatter.format(fileDate);
}
|
楼上好牛!