Java File Name Create addTimeStampToFileName(String name)

Here you can find the source of addTimeStampToFileName(String name)

Description

add Time Stamp To File Name

License

Open Source License

Declaration

public static String addTimeStampToFileName(String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static String addTimeStampToFileName(String name) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy 'at' HH.mm.ss", Locale.ENGLISH);
        Date currentDate = new Date();
        String formattedDate = dateFormat.format(currentDate);

        int index = name.lastIndexOf(".");

        String mainFName;/*from   w  ww . ja v  a2s  .  c  om*/
        if (index != -1) {
            mainFName = name.substring(0, index - 1) + " " + formattedDate
                    + name.substring(index - 1, name.length());
        } else {
            mainFName = name + " " + formattedDate + ".log";
        }

        return mainFName;
    }
}

Related

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