【问题标题】:How to save recorder audio with current date and time format如何以当前日期和时间格式保存录音机音频
【发布时间】:2017-04-19 18:34:05
【问题描述】:
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]);
    }

我想以当前日期和时间格式保存我的文件,因为我录制的文件没有以当前日期和时间格式保存。

【问题讨论】:

  • 您已经成功保存了文件,但是文件名与您想要的不一样(当前日期和时间格式),对吧?
  • 是的,我想用当前日期和时间格式保存我的文件。
  • 使用SimpleDateFormat。这里有一些例子stackoverflow.com/questions/6406470/java-simpledateformat

标签: android


【解决方案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]); 

【讨论】:

  • 让我试试这个:)
  • 非常感谢,这对我有用,我被困了好几个小时。
  • 乐于助人。请在使用之前检查函数文档。 System.currentTimeMillis() 方法返回当前时间与 UTC 1970 年 1 月 1 日午夜之间的差异,以毫秒为单位。
猜你喜欢
  • 1970-01-01
  • 2012-06-09
  • 2020-04-11
  • 2019-09-08
  • 2017-08-20
  • 1970-01-01
  • 2012-09-06
  • 2020-09-26
相关资源
最近更新 更多