import java.sql.Date;
import java.text.SimpleDateFormat;
File openf=new File(filename);
SimpleDateFormat dd =new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now=new Date(openf.lastModified());
dd.setTimeZone(TimeZone.getTimeZone("GMT"));
watchtime=dd.format(now );//watchtime是字符串
本文展示了一个使用Java读取文件最后修改时间的例子,并将其格式化为特定的时间字符串格式。涉及的操作包括设置日期格式、获取文件对象、读取文件最后修改时间并转换为指定格式。
9491

被折叠的 条评论
为什么被折叠?



