Here you can find the source of getCurrentSecondZeroFillString()
public static String getCurrentSecondZeroFillString()
//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(); /**// w w w .j a v a 2s.com * Returns a string of timestamp with second precision and the length of * {@code LONG_TYPE_MAX_LENGTH}. * * @return A string of timestamp. */ public static String getCurrentSecondZeroFillString() { return getCurrentSecondZeroFillString(LONG_TYPE_MAX_LENGTH); } /** * Returns a string of timestamp with second 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 getCurrentSecondZeroFillString(int length) { return getLeftZeroFillString(System.currentTimeMillis() / 1000, 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); } }