Java Time Now currentTimeString(String pattern)

Here you can find the source of currentTimeString(String pattern)

Description

Formats NOW into a specific pattern.

License

Apache License

Parameter

Parameter Description
pattern a parameter

Declaration

public static String currentTimeString(String pattern) 

Method Source Code


//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());
    }
}

Related

  1. currentTimedDate()
  2. currentTimeMillis()
  3. currentTimePath(String basePath)
  4. currentTimeStr()
  5. currentTimeString()
  6. currtimeToString8()
  7. get_cur_datetime()
  8. getCurDateBefore(long time)
  9. getCurDateTime()