Java Date Now getCurrentDate()

Here you can find the source of getCurrentDate()

Description

get Current Date

License

Apache License

Declaration

public static Date getCurrentDate() 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date getCurrentDate() {
        Date now = getCurrentDateTime();
        return strToDate(dateToStr(now));
    }/*from   ww  w. j  a v  a 2  s.c o m*/

    /**
     * @return
     */
    public static Date getCurrentDateTime() {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        return calendar.getTime();
    }

    public static Date strToDate(String s) {
        Date d = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            d = sdf.parse(s);
        } catch (Exception e) {

        }

        return d;
    }

    public static String dateToStr(Date date) {
        String s = "";
        if (date == null) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            s = sdf.format(date);
        } catch (Exception e) {

        }

        return s;
    }
}

Related

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