【问题标题】:android create File name using datetimeandroid使用日期时间创建文件名
【发布时间】:2014-03-26 11:05:26
【问题描述】:

我有一个问题,我如何使用这种日期时间格式 (dd-mm-yyyy hh:mm:ss) 而不是这个 (dd-mm-yyyy hh-mm-ss) 创建一个名称为完整日期时间的文件夹。

例如:

这一行创建文件夹。

String outString = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File dossierphoto = new File(Environment.getExternalStorageDirectory() + "/Dossier Client/" + cli.getClientId() + "/" + outString);

但是这条线没有任何作用

String outString = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss").format(new Date());
File dossierphoto = new File(Environment.getExternalStorageDirectory() + "/Dossier Client/" + cli.getClientId() + "/" + outString);

【问题讨论】:

  • 你没有调用创建文件..在这两行之后调用这个 dossierphoto.createNewFile();..

标签: android file datetime


【解决方案1】:

试试这个

// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String FileName = JPEG_FILE_PREFIX + timeStamp + "_";
File F = File.createTempFile(FileName, "IMG_");

【讨论】:

    【解决方案2】:
       filename = "Trim"
                        + (new SimpleDateFormat("yyyyMMdd_HHmmss", Locale
                                .getDefault())).format(new Date()) + ".mp4";
    

    【讨论】:

      【解决方案3】:

      你可以试试这个方法

      static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
      static String todayDate = dateFormat.format(new Date());
      
      File file = new File(Environment.getExternalStorageDirectory() + "/Dossier Client/"+todayDate);
      
      if (!file.exists()) {
                  try {
                      file.mkdir();
      
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2011-07-11
        • 2010-09-25
        • 2015-11-17
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        • 2014-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多