Here you can find the source of currentTimeToString(int format, String delimiter)
public static String currentTimeToString(int format, String delimiter)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String[] SIMPLE_TIME_FORMAT = { "yyyy-MM-dd", "yyyy-MM-dd-HH", "yyyy-MM-dd-HH-mm", "yyyy-MM-dd-HH-mm-ss" }; public static String currentTimeToString(int format, String delimiter) { return formatDate(new Date(), format, delimiter); }/* ww w .j a v a 2s. c o m*/ public static String formatDate(long timeMilliSeconds, int format) { return formatDate(new Date(timeMilliSeconds), format, ""); } public static String formatDate(long timeMilliSeconds, int format, String delimiter) { return formatDate(new Date(timeMilliSeconds), format, delimiter); } private static String formatDate(Date date, int format, String delimiter) { return formatDate(format, delimiter).format(date); } private static SimpleDateFormat formatDate(int format, String delimiter) { assert format >= 0 && format < SIMPLE_TIME_FORMAT.length; String formatString = SIMPLE_TIME_FORMAT[format]; if (delimiter != null) { formatString = formatString.replace("-", delimiter); } return new SimpleDateFormat(formatString); } }