Here you can find the source of getCurrentTimeString()
public static String getCurrentTimeString()
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static String getCurrentTimeString() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); String second = cal.get(Calendar.SECOND) < 10 ? "0" + cal.get(Calendar.SECOND) : "" + cal.get(Calendar.SECOND); String minute = cal.get(Calendar.MINUTE) < 10 ? "0" + cal.get(Calendar.MINUTE) : "" + cal.get(Calendar.MINUTE); String hour = cal.get(Calendar.HOUR_OF_DAY) < 10 ? "0" + cal.get(Calendar.HOUR_OF_DAY) : "" + cal.get(Calendar.HOUR_OF_DAY); String strDate = cal.get(Calendar.YEAR) + (cal.get(Calendar.MONTH) + 1) + cal.get(Calendar.DAY_OF_MONTH) + hour + minute + second; return strDate; }//from w ww.j a v a 2 s . co m }