2015-10-16 56 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(); 
相关问题