JNPW JNPW - 1 month ago 11
Java Question

java date in mmddhhmmss format

I want to add date to the file so i maintain archive.
I want date in this format: mmddhhmmss

So the file name is "cGroup0307131614", just that i want to add timestamp.
Not necessary it should be mmddhhmmss format but a format that maintains timestamp.

I tried the foll:

java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));


But o/p is 2013-03-07 14:59:30.252. I dont want any spaces colons or special characters.

Answer
SimpleDateFormat simpleDateFormat =
            new SimpleDateFormat("MMddhhmmss");
String dateAsString = simpleDateFormat.format(new Date());
System.out.println(dateAsString);

Output:

0307114712