Here you can find the source of getYYYYMMDDHHMISS()
public static String getYYYYMMDDHHMISS()
//package com.java2s; /******************************************************************************* * @(#)DateFormatUtil.java 2012-3-12// w ww .java2 s . com * * Copyright 2012 Neusoft Group Ltd. All rights reserved. * Neusoft PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *******************************************************************************/ import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getYYYYMMDDHHMISS() { return getYYYYMMDD() + getHHMISSSSS(); } public static String getYYYYMMDD() { Calendar cal = Calendar.getInstance(); String dateStr = "" + cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; if (month < 10) { dateStr = dateStr + "0" + month; } else { dateStr = dateStr + "" + month; } int day = cal.get(Calendar.DAY_OF_MONTH); if (day < 10) { dateStr = dateStr + "0" + day; } else { dateStr = dateStr + "" + day; } return dateStr; } public static String getYYYYMMDD(int y, int m, int d) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, y); cal.add(Calendar.MONTH, m); cal.add(Calendar.DATE, d); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); return format.format(cal.getTime()); } public static String getHHMISSSSS() { Calendar cal = Calendar.getInstance(); String dateStr = ""; int hour = cal.get(Calendar.HOUR_OF_DAY); dateStr = zeroSupply("" + hour, 2); int minute = cal.get(Calendar.MINUTE); dateStr = dateStr + zeroSupply("" + minute, 2); int sec = cal.get(Calendar.SECOND); dateStr = dateStr + zeroSupply("" + sec, 2); int msec = cal.get(Calendar.MILLISECOND); dateStr = dateStr + zeroSupply("" + msec, 3); return dateStr; } public static String zeroSupply(String value, int len) { if (value == null) { return value; } String supply = ""; for (int i = value.length(); i < len; i++) { supply = supply + "0"; } return supply + value; } }