Java Time Now getNowTime(String format, Locale loc)

Here you can find the source of getNowTime(String format, Locale loc)

Description

get Now Time

License

Apache License

Declaration

public static String getNowTime(String format, Locale loc) 

Method Source Code

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

import java.util.Date;

import java.util.Locale;

public class Main {

    public static String getNowTime(String format, Locale loc) {
        if (format == null) {
            format = "yyyy-MM-dd HH:mm:ss";
        }//w ww  .j av  a2s .  c om

        if (loc == null)
            return new java.text.SimpleDateFormat(format).format(java.util.Calendar.getInstance().getTime());

        return new java.text.SimpleDateFormat(format, loc).format(java.util.Calendar.getInstance().getTime());
    }

    public static String getNowTime(String format) {
        return getNowTime(format, null);
    }

    public static String getNowTime() {
        return getNowTime(null);
    }

    public static Long getTime(int length, Date date) {
        String time = String.valueOf(date.getTime()).substring(0, length);
        return Long.parseLong(time);
    }
}

Related

  1. getNowTime()
  2. getNowTime()
  3. getNowTime()
  4. getNowTime()
  5. getNowTime(String format)
  6. getNowTime(String formatStr)
  7. getNowWithLocal(boolean ifdatetime)
  8. getNowYearMonth()
  9. getNowYMD()