2012-12-01 56 views

回答

3

完全相同的方式。日期包含一個即時的時間,精度爲毫秒。只需更改用於解析日期的格式即可。爲此,請閱讀the documentation

2

在Java 7中,可以創建時間設定爲使用這樣的代碼的目錄或文件:

//date which is used as date of creation 
Date creationDate; 
//path to directory of file to which to set creation time 
Path somePath; 
... 
FileTime time = FileTime.fromMillis(creationDate.getTime()); 
Files.setAttribute(somePath, "creationTime", time); 
0

這並不使用HFS文件系統上的MAC工作的OSX一個UNIX變體。

import java.io.*; 
import java.util.*; 
import java.nio.*; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.nio.file.attribute.FileTime; 
import static java.nio.file.LinkOption.NOFOLLOW_LINKS; 

class changetime{ 

    public static void main(String args[]){ 

     Path p = Paths.get("./test.txt"); 
     System.out.println(p); 
     try { 
       Calendar c = Calendar.getInstance(); 
       c.set(2010, Calendar.MARCH, 20); 
       Files.setAttribute(p, "basic:creationTime", FileTime.fromMillis(c.getTimeInMillis()), NOFOLLOW_LINKS); 
     } catch (IOException e) { 
       System.err.println("Cannot change the creation time. " + e); 
     } 
    }//END Main 

}//END Class 
相關問題