JAVA IO - 最後修改日期

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日期 java

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()));
    }
}
相關文章
相關標籤/搜索