Java SQL Date Create beginOfDay(Date date)

Here you can find the source of beginOfDay(Date date)

Description

begin Of Day

License

Open Source License

Declaration

public static Date beginOfDay(Date date) 

Method Source Code


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

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date beginOfDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);//from w  w  w.  jav a  2s  .  c  o  m
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    public static Timestamp beginOfDay(Timestamp timestamp) {
        Calendar c = Calendar.getInstance();
        c.setTime(timestamp);
        c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        c.set(Calendar.MILLISECOND, 0);
        return new Timestamp(c.getTimeInMillis());
    }
}

Related

  1. asDate(Object tsObj)
  2. asSqlDate(Date date)
  3. asSqlDate(Date date)
  4. asSqlDate(String date)
  5. beforeNow(final Date d)
  6. castToSqlDate(Object value)
  7. convert(Date date)
  8. convertDate(java.sql.Date date)
  9. convertDateFromSQLDate(java.sql.Date sqlDate)