Java Time Now getNowTime()

Here you can find the source of getNowTime()

Description

get Now Time

License

Open Source License

Declaration

public static Date getNowTime() 

Method Source Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date getNowTime() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String dateStr = dateFormat(date);
        try {//from  w w w  .  j  a  v  a 2  s .c  om
            date = format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date dateFormat(String date, String dateFormat) {
        if (date == null)
            return null;
        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        if (date != null)
            try {
                return format.parse(date);
            } catch (Exception ex) {
            }
        return null;
    }

    public static Date dateFormat(String date) {
        return dateFormat(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateFormat(Date date, String dateFormat) {
        if (date == null)
            return "";
        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        if (date != null)
            return format.format(date);

        return "";
    }

    public static String dateFormat(Date date) {
        return dateFormat(date, "yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. getNowTime()
  2. getNowTime()
  3. getNowTime()
  4. getNowTime()
  5. getNowTime()
  6. getNowTime()
  7. getNowTime(String format)
  8. getNowTime(String format, Locale loc)
  9. getNowTime(String formatStr)