Java Date Now getNowDate()

Here you can find the source of getNowDate()

Description

get Now Date

License

Open Source License

Declaration


public static Date getNowDate() 

Method Source Code


//package com.java2s;

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

public class Main {

    public static Date getNowDate() {

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        ParsePosition pos = new ParsePosition(8);
        Date currentTime_2 = formatter.parse(dateString, pos);
        return currentTime_2;
    }/*from   w  w w . j  ava2s.  c o m*/

    public static String format(java.util.Date date, String format, Calendar calendar) {
        String result = "";
        try {
            if (date != null) {
                java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
                if (calendar != null) {
                    sdf.setCalendar(calendar);
                }
                result = sdf.format(date);
            }
        } catch (Exception e) {
        }

        return result;
    }

    public static String format(java.util.Date date, String format) {
        return format(date, format, null);
    }

    public static String format(long times, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(times);
        return format(calendar.getTime(), format);
    }

    public static String getTime() {

        Date currentTime = new Date();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateString = formatter.format(currentTime);

        String min;

        min = dateString.substring(14, 16);

        return min;

    }
}

Related

  1. getCurrentYear()
  2. getCurrentYearBegDate(Date date)
  3. getCurrentYMDDate()
  4. getCurrentZeroTime()
  5. getDayToMonthEnd(boolean iscurrentdate)
  6. getNowDate()
  7. getNowDate()
  8. getNowDate()
  9. getNowDate()