Java Time Now getNowStr()

Here you can find the source of getNowStr()

Description

get current date and time string

License

Apache License

Return

a local datetime string

Declaration

public static String getNowStr() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.*;
import java.util.*;

public class Main {
    public static final String FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";

    /**/*from  ww w.  j  a va  2  s.  com*/
     * get current date and time string
     * 
     * @return a local datetime string
     */
    public static String getNowStr() {
        return format(new Date(), FORMAT_DATE_TIME);
    }

    /**
     * get date string use pattern
     * 
     * @param pattern
     *            see {@link java.text.SimpleDateFormat}
     * @return a date string
     */
    public static String format(String pattern) {
        return format(new Date(), pattern);
    }

    /**
     * get date string use pattern
     * 
     * @param pattern
     *            see {@link java.text.SimpleDateFormat}
     * @return a date string
     */
    public static String format(Date date, String pattern) {
        SimpleDateFormat dateFormater = new SimpleDateFormat(pattern);
        return dateFormater.format(date);
    }
}

Related

  1. getNowInBanFormat()
  2. getNowInputDate()
  3. getNowOfDateByFormat(String format)
  4. getNowPatch()
  5. getNowSinceHour()
  6. getNowStr()
  7. getNowStr()
  8. getNowStrDateVerbose()
  9. getNowString()