Java Date Now getCurrentTime()

Here you can find the source of getCurrentTime()

Description

get Current Time

License

Open Source License

Declaration

public static String getCurrentTime() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String getCurrentTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        Date date = new Date(System.currentTimeMillis());
        return sdf.format(date);
    }/*  www  . j  a  va2  s .co m*/

    public static String format(String str, Object... args) {
        if (isEmptyOrNull(str))
            return "";
        if (args.length == 0)
            return str;
        String result = str;
        Pattern p = java.util.regex.Pattern.compile("\\{(\\d+)\\}");
        Matcher m = p.matcher(str);
        while (m.find()) {
            int index = Integer.parseInt(m.group(1));
            if (index < args.length) {
                result = result.replace(m.group(), args[index].toString());
            }
        }
        return result;
    }

    public static boolean isEmptyOrNull(String str) {
        return str == null || str.length() == 0 || str.contentEquals("null") || str.trim().equals("");
    }
}

Related

  1. getCurrentStringDateYMD()
  2. getCurrentStrTimeMills()
  3. getCurrentTime()
  4. getCurrentTime()
  5. getCurrentTime()
  6. getCurrentTime()
  7. getCurrentTime()
  8. getCurrentTime()
  9. getCurrentTime()