Here you can find the source of getCurrentMillisecondZeroFillString()
public static String getCurrentMillisecondZeroFillString()
//package com.java2s; //License from project: Apache License public class Main { private static final int LONG_TYPE_MAX_LENGTH = String.valueOf(Long.MAX_VALUE).length(); /**//from www . j av a 2 s.c om * Returns a string of timestamp with millisecond precision and the length * of {@code LONG_TYPE_MAX_LENGTH}. * * @return A string of timestamp. */ public static String getCurrentMillisecondZeroFillString() { return getCurrentMillisecondZeroFillString(LONG_TYPE_MAX_LENGTH); } /** * Returns a string of timestamp with millisecond precision and the length * of {@code length}. * * @param length * the length of timestamp to return * @return A string of timestamp. * @throws IllegalArgumentException * If {@code length} is less than the length of current * timestamp */ public static String getCurrentMillisecondZeroFillString(int length) { return getLeftZeroFillString(System.currentTimeMillis(), length); } /** * Returns a left zero-filled string of a long. * * @param src * a long to left zero-fill * @param length * the length of zero-filled string * @return A string containing left zero-filled long */ private static String getLeftZeroFillString(long src, int length) throws IllegalArgumentException { char[] numberChars = String.valueOf(src).toCharArray(); int numberLength = numberChars.length; if (length < numberLength) { throw new IllegalArgumentException( "String length must be equal or greater than current timestamp's length:" + numberLength + "."); } char[] result = new char[length]; for (int i = 0; i < length; i++) { result[i] = '0'; } int pos = length - numberLength; for (char digit : numberChars) { result[pos] = digit; pos++; } return String.copyValueOf(result); } }