您的位置:首页 > 编程语言 > Java开发

JAVA IO - 最后修改日期

2014-01-10 00:00 274 查看
import java.io.File;
import java.text.SimpleDateFormat;

public class LastModifiedDate {
public static void main(String args[]){
File file = new File("C:\\work\\hello\\helloworld.txt");
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
System.out.println("Last modify date " + format.format(file.lastModified()));
}
}

修改最后modify日期

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LastModifiedDate {
public static void main(String args[]) throws Exception{
File file = new File("C:\\work\\hello\\helloworld.txt");
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
System.out.println("Last modify date " + format.format(file.lastModified()));

SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
//set this date
String newLastModified = "01/01/2014";

//need convert the above date to milliseconds in long value
Date newDate = format1.parse(newLastModified);
file.setLastModified(newDate.getTime());

System.out.println("Last modify date after changing " + format.format(file.lastModified()));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: