Here you can find the source of currentDateTimeMillis()
public static String currentDateTimeMillis()
//package com.java2s; import java.util.Calendar; import java.util.TimeZone; public class Main { public static String currentDateTimeMillis() { Calendar dt = Calendar.getInstance(TimeZone.getDefault()); String strYear = dt.get(Calendar.YEAR) + ""; int iTmp = dt.get(Calendar.MONTH) + 1; String strMonth = iTmp + ""; String strDay = dt.get(Calendar.DAY_OF_MONTH) + ""; String hour = (dt.get(Calendar.HOUR_OF_DAY) < 10) ? "0" + dt.get(Calendar.HOUR_OF_DAY) : dt.get(Calendar.HOUR_OF_DAY) + ""; String minute = (dt.get(Calendar.MINUTE) < 10) ? "0" + dt.get(Calendar.MINUTE) : dt.get(Calendar.MINUTE) + ""; String second = (dt.get(Calendar.SECOND) < 10) ? "0" + dt.get(Calendar.SECOND) : dt.get(Calendar.SECOND) + ""; String millisecond = ("000" + dt.get(Calendar.MILLISECOND)).substring(3); StringBuffer sb = new StringBuffer(); sb.append(dateFormat(strYear, strMonth, strDay)).append(hour).append(minute).append(second) .append(millisecond);/*ww w .jav a 2 s . c o m*/ return sb.toString(); } static public String dateFormat(String strYear, String strMonth, String strDay) { if (strYear == null || strYear.equals("")) return ""; if (strMonth == null || strMonth.equals("")) return ""; if (strDay == null || strDay.equals("")) return ""; strYear = strYear.trim();// year must be 4 digits. strMonth = strMonth.trim(); if (strMonth.length() == 1) strMonth = "0" + strMonth; strDay = strDay.trim(); if (strDay.length() == 1) strDay = "0" + strDay; String strDate = strYear + strMonth + strDay; return strDate; } }