Java File Name Create addTimestampToFilename(String fileName)

Here you can find the source of addTimestampToFilename(String fileName)

Description

add Timestamp To Filename

License

Open Source License

Declaration

public static String addTimestampToFilename(String fileName) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

public class Main {
    public static final String fileTimestampFormat = "yyyy-MM-dd'T'HH.mm.ss.SSSZ";

    public static String addTimestampToFilename(String fileName) {
        int pos = fileName.lastIndexOf('.');
        String prefix = fileName;
        String suffix = "";
        if (pos != -1) {
            prefix = fileName.substring(0, pos);
            suffix = fileName.substring(pos);
        }//from ww  w .  j a  v  a2  s .c o m
        String newFileName = prefix + timestampForFile() + suffix;
        return newFileName;
    }

    public static String timestampForFile() {
        String timeString = new SimpleDateFormat(fileTimestampFormat).format(System.currentTimeMillis());
        return timeString;
    }
}

Related

  1. addTimeStampGetPostFix(Date now, TimeUnit unit)
  2. addTimestampToFilename(Date date, String fileName)
  3. addTimeStampToFileName(String name)
  4. fileName(Class clazz)
  5. filename(final String path)
  6. fileName(String contentFile)