Java date format is mmddhhmmss

I want to add a date to the file to maintain the archive

So the file name is "cgroup0307131614", but I want to add a timestamp Needless to say, it should be in mmddhhmmss format, but a format that maintains time stamps

I tried this:

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

But o / P is 14:59:30.252 on March 7, 2013 I don't want any spaces, colons or special characters

Solution

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

Output:

0307114712
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>