Here you can find the source of getCurrentTimeAsString()
public static String getCurrentTimeAsString()
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.util.Calendar; public class Main { /**/*from w ww . j a v a 2 s . c o m*/ * Get current Time. * @return Time in HHmmssSS format. */ public static String getCurrentTimeAsString() { Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); String mDateFormat = ""; DecimalFormat twoDigitFormat = new DecimalFormat("00"); mDateFormat = twoDigitFormat.format(hour) + twoDigitFormat.format(minute) + twoDigitFormat.format(second) + twoDigitFormat.format(millisecond); return mDateFormat; } }