Here you can find the source of getCurrentDateStamp()
public static String getCurrentDateStamp()
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /** Get current Date stamp * @return The Current Date/Time in the format: yyyymmdd_hhmm */// www.j a va2 s.c o m public static String getCurrentDateStamp() { return convertToDateStamp(System.currentTimeMillis()); } /** Convert given date to string<br> * OutputFormat: yyyymmdd_hhmm * @return The Date/Time in the format: yyyymmdd_hhmm */ public static String convertToDateStamp(long time) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(time)); return convertToDateStamp(cal); } /** Convert given date to string<br> * OutputFormat: yyyymmdd_hhmm * @return The Date/Time in the format: yyyymmdd_hhmm */ public static String convertToDateStamp(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return convertToDateStamp(cal); } /** Convert given date to string<br> * OutputFormat: yyyymmdd_hhmm * @return The Date/Time in the format: yyyymmdd_hhmm */ public static String convertToDateStamp(Calendar cal) { String year = String.valueOf(cal.get(Calendar.YEAR)); String month = String.valueOf(cal.get(Calendar.MONTH) + 1); if (month.length() == 1) { month = "0" + month; } String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); if (day.length() == 1) { day = "0" + day; } String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); if (hour.length() == 1) { hour = "0" + hour; } String minute = String.valueOf(cal.get(Calendar.MINUTE)); if (minute.length() == 1) { minute = "0" + minute; } String second = String.valueOf(cal.get(Calendar.SECOND)); if (second.length() == 1) { second = "0" + second; } String dateStamp = year + month + day + "_" + hour + minute + second; return dateStamp; } }