create Timestamped Zip Filename - Java java.io

Java examples for java.io:File Name

Description

create Timestamped Zip Filename

Demo Code

/*/* w w  w  . ja  v a 2  s.  c  om*/
 * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
 */
//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        String prefix = "java2s.com";
        System.out.println(createTimestampedZipFilename(prefix));
    }

    private final static ThreadLocal<SimpleDateFormat> DATE_FORMATTER = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyyMMddHHmmss");
        }
    };

    public static String createTimestampedZipFilename(String prefix) {
        StringBuilder sb = new StringBuilder(prefix);
        sb.append("-");
        sb.append(DATE_FORMATTER.get().format(new Date()));
        sb.append(".zip");
        return sb.toString();
    }
}

Related Tutorials