JNPW JNPW - 1 year ago 131
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 Source
SimpleDateFormat simpleDateFormat =
            new SimpleDateFormat("MMddhhmmss");
String dateAsString = simpleDateFormat.format(new Date());


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download