2017-04-19 83 views
0
private String getFilename() { 
     String filepath = Environment.getExternalStorageDirectory().getPath(); 
     File file = new File(filepath, AUDIO_RECORDER_FOLDER); 
     if (!file.exists()) { 
      file.mkdirs(); 
     } 
     return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]); 
    } 

我想用當前日期和時間格式保存我的文件,因爲我的錄製文件未使用當前日期和時間格式進行保存。如何使用當前日期和時間格式保存錄音機音頻

+0

您已成功保存了文件,但該文件的名稱是不喜歡你想要的(當前日期和時間格式) , 對? –

+0

是的,我想用當前的日期和時間格式保存我的文件。 –

+1

使用'SimpleDateFormat'。這裏有一些例子http://stackoverflow.com/questions/6406470/java-simpledateformat – nandsito

回答

1

而不是做這個的:

return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]); 

做到這一點:

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
return (file.getAbsolutePath() + "/" + timeStamp + file_exts[currentFormat]); 
+0

讓我試試:) –

+0

非常感謝這對我來說是工作,我從很多小時卡住了。 –

+0

樂意幫忙。在使用它們之前,請檢查功能的文檔。 'System.currentTimeMillis()'方法返回當前時間和1970年1月1日午夜UTC之間的差值,以毫秒爲單位。 –

相關問題