2015-10-16 47 views

回答

0

如果我明白你的問題,這種方法可以幫助你:

try 
{ 
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
    File file = new File("path_to_your_file"); 

    //set this date 
    String the_date_you_want_to_set = "16/10/2015"; 

    Date modifiedDate = simpleDateFormat.parse(the_date_you_want_to_set=); 
    file.setLastModified(modifiedDate.getTime()); 
} 
catch(ParseException e) 
{ 
    e.printStackTrace(); 
} 
0

也許這如果你在談論JPEG照片會有幫助。這改變了圖像的元數據:

import android.media.ExifInterface; 
import java.util.*; 

.... 

ExifInterface exif = new ExifInterface(filename); 
String date = exif.getAttribute(ExifInterface.TAG_DATETIME); //or TAG_DATETIME_DIGITIZED or TAG_GPS_DATESTAMP or TAG_GPS_TIMESTAMP 
if(date == null) //do something; 

做任何處理是必要的,以確定該日期是什麼。然後,保持字符串的格式,改變它,以便它反映第二天。遞增一天的一種方法是

GregorianCalendar c = new GregorianCalendar(year,month,day); 
c.add(Calendar.DATE,1); 
int updatedYear = c.get(Calendar.YEAR); 
int updatedMonth = c.get(Calendar.MONTH); 
int updatedDay = c.get(Calendar.DATE); 

然後更新文件:

exif.setAttribute(ExifInterface.TAG_DATETIME, updatedDate); //use whichever TAG_ you used in the first part 
exif.saveAttributes(); 
相關問題