Java Today getFirstDate(Date today)

Here you can find the source of getFirstDate(Date today)

Description

get First Date

License

Open Source License

Declaration

public static Date getFirstDate(Date 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 {
    public static final String DF_YMD = "yyyy-MM-dd";
    public static final String DF_HMS = "HH:mm:ss";

    public static Date getFirstDate(Date today) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);/* ww  w  .  j ava2  s  .  co m*/
        calendar.set(Calendar.DATE, 1);

        return calendar.getTime();
    }

    public static String getTime() {
        return dateToString(now(), DF_HMS);
    }

    public static String getTime(Date trialTime) {
        return dateToString(trialTime, DF_HMS);
    }

    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        }
        synchronized (date) {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.format(date);
        }
    }

    public static String dateToString(Date date) {
        return dateToString(date, DF_YMD);
    }

    public static Date now() {
        return new Date();
    }
}

Related

  1. formatToDays(Date date)
  2. getAllToday()
  3. getBetweenTodaysStartDateAndEndDate(Date startDate, Date endDate)
  4. getCalendarTodayZero(Calendar today)
  5. getEndOfToday()
  6. getLastCalendarOfToday()
  7. getNDaysFromToday(int n)
  8. getSomedayAfterToday(int x)
  9. getStartOfDayRelative(int daysFromToday)