Java Today today()

Here you can find the source of today()

Description

today

License

Open Source License

Declaration

public static int today() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static SimpleDateFormat intSDF = new SimpleDateFormat("yyyyMMdd");
    private static final SimpleDateFormat defaultFormater = new SimpleDateFormat("yyyyMMdd");
    private static final SimpleDateFormat customizedFormater = new SimpleDateFormat("yyyyMMdd");

    public static int today() {
        return systemDate(0);
    }//from w  w w .ja  v  a2  s.  c  om

    public static int systemDate(int date) {
        @SuppressWarnings("unused")
        Calendar c = Calendar.getInstance();
        Date d = new Date();
        return Integer.parseInt(intSDF.format(new Date(d.getTime() + (long) date * 24 * 60 * 60 * 1000)));
    }

    public static String format(Date date, String pattern) {
        synchronized (customizedFormater) {
            if (null != pattern && !"".equals(pattern.trim())) {
                customizedFormater.applyPattern(pattern);
            } else {
                throw new IllegalArgumentException("pattern can not be empty");
            }
            return customizedFormater.format(date);
        }
    }

    public static String format(Date date) {
        synchronized (defaultFormater) {
            return defaultFormater.format(date);
        }
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(currentTime);
    }
}

Related

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