Here you can find the source of currentTimeString(String pattern)
Parameter | Description |
---|---|
pattern | a parameter |
public static String currentTimeString(String pattern)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String STANDARD_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static SimpleDateFormat standardFormat; /**/* ww w. ja v a 2 s .co m*/ * Formats NOW into a pattern "yyyy-MM-dd HH:mm:ss" * * @return */ public static String currentTimeString() { if (standardFormat == null) { standardFormat = new SimpleDateFormat(STANDARD_PATTERN); } return standardFormat.format(new Date()); } /** * Formats NOW into a specific pattern. * * @param pattern * @return */ public static String currentTimeString(String pattern) { SimpleDateFormat df = new SimpleDateFormat(pattern); return df.format(new Date()); } }