John Snow
John Snow

Reputation: 21

android create File name using datetime

I have a question , how can i create a folder with name full datetime using this datetime format (dd-mm-yyyy hh:mm:ss) and not this (dd-mm-yyyy hh-mm-ss).

for example :

this line create folder.

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

but this line doesn't do anything

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

Upvotes: 1

Views: 8002

Answers (3)

Anil Kanani
Anil Kanani

Reputation: 270

   filename = "Trim"
                    + (new SimpleDateFormat("yyyyMMdd_HHmmss", Locale
                            .getDefault())).format(new Date()) + ".mp4";

Upvotes: 1

krishna
krishna

Reputation: 142

you can try this method

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();
        }
    }

Upvotes: 0

Muhammad Aamir Ali
Muhammad Aamir Ali

Reputation: 21097

Try this

// 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_");

Upvotes: 4

Related Questions