Here you can find the source of addTimeStampToFileName(String name)
public static String addTimeStampToFileName(String name)
//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; } }