0

I am new to android. i have video recording application where in i capture the video and store it, i need to store the video's name with the current date and time. so is there any way to do the same. Till i know the video names does not take the number format values..

String mediaFile;
        File mediaStorageDir = new File(
                Environment.getExternalStorageDirectory(), "/VideoLogger");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("VideoLogger", "failed to create directory");
                return null;
            }
        }
        String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
                .format(new Date());
        if (!sufix.equals("movie")) {
            mediaFile = mediaStorageDir.getPath() + File.separator + "output_"
                    + timeStamp + "_" + sufix + ".txt";
        } else {
            mediaFile = mediaStorageDir.getPath() + File.separator + "output_"
                    + timeStamp + ".mp4";

        }

        return mediaFile;
    }
}

Here is the code that i use for naming my video file.

android_developer
  • 663
  • 2
  • 13
  • 18

3 Answers3

0

Use this code

Date date=new Date();
filename="/rec"+date.toString().replace(" ", "_").replace(":", "_")+".mp4";
Sam
  • 86,580
  • 20
  • 181
  • 179
Priya
  • 1,763
  • 1
  • 12
  • 11
0

You can use this code:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
                        String formattedDate = df.format(c.getTime());

NOTE: you can change this: "yyyy-MM-dd HH.mm.ss" to whatever you want, like "yyyy_MM_dd_HH-mm-ss"

EDIT: just in case you need to add this

Calendar c = Calendar.getInstance();
Rotary Heart
  • 1,899
  • 3
  • 29
  • 44
0

SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");//Give you current date currentDate = date.format(new Date());SimpleDateFormat time = new SimpleDateFormat("hh:mm a");//Give you current time currentTime = time.format(new Date());//Store like this filename = currentDate +"-"+currentTime +".mp4";