如何将带日期的文件存入SD卡?

How to store file with date into SD card?

在我的应用程序中,我想将文件存储到 SD 卡中。
我想要的是,当应用程序存储此文件时,将现在的日期添加为文件名,为此我编写了以下代码。

但是当用户将设备语言更改为 UTF-8 语言(例如:波斯语 - 阿拉伯语 , ...) 文件以 UTF-8 字符存储!

例如: 使用此名称存储文件:COM_MyVideo_۲۰۲۰-۱-۵
但我想要这个名字的商店:COM_MyVideo_2020-1-5

我的代码:

private String getFileSaveName() {
    videoName = GoodPrefs.getInstance().getString(ConstKeys.TEST_NAME, "MyApp");
    videoName = videoName + "-" + GoodPrefs.getInstance().getInt(ConstKeys.TEST_ID, 0) + "-";
    String filename = "yyyyMMdd_HHmmss";
    //Required to handle preference change
    filename = filename.replace("hh", "HH");
    String prefix = "COM_" + videoName;
    Date today = Calendar.getInstance().getTime();
    SimpleDateFormat formatter = new SimpleDateFormat(filename);
    return prefix + formatter.format(today);
}

我该如何解决?

试试他的,首先创建当前日期时间作为时间戳,然后将时间戳转换为本地英文日期,并根据需要进行格式化。

 Date date= new Date();

 long time = date.getTime();

 Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    cal.setTimeInMillis(time * 1000);
    String date = DateFormat.format("dd-MM-yyyy", cal).toString();