Java Time Now getNowTime()

Here you can find the source of getNowTime()

Description

return current time value in format: yyyy-MM-dd HH:mm:ss:sss

License

Apache License

Return

String value

Declaration

public static String getNowTime() 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//from  w w  w .  j a v a2s  . c o  m
     * return current time value in format: yyyy-MM-dd HH:mm:ss:sss
     *
     * @return String value
     */
    public static String getNowTime() {
        return dateToStringWithPattern(new Date(), "yyyy-MM-dd HH:mm:ss:sss");
    }

    /**
     * return time value of specified date
     *
     * @param date    the specified date to convert
     * @param pattern time format
     * @return String value
     */
    public static String dateToStringWithPattern(Date date, String pattern) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. getNowTime()
  2. getNowTime()
  3. getNowTime()
  4. getNowTime()
  5. getNowTime()
  6. getNowTime()
  7. getNowTime()
  8. getNowTime()
  9. getNowTime()