Java Timestamp Field getNextDayStart(java.sql.Timestamp stamp)

Here you can find the source of getNextDayStart(java.sql.Timestamp stamp)

Description

get Next Day Start

License

Apache License

Declaration

public static java.sql.Timestamp getNextDayStart(java.sql.Timestamp stamp) 

Method Source Code


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

import java.sql.Timestamp;

import java.util.Calendar;
import java.util.Date;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static java.sql.Timestamp getNextDayStart(java.sql.Timestamp stamp) {
        return getDayStart(stamp, 1);
    }//from   ww  w  . j  a  v a  2s  . c  o m

    public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp) {
        return getDayStart(stamp, 0);
    }

    public static java.sql.Timestamp getDayStart(java.sql.Timestamp stamp, int daysLater) {
        return getDayStart(stamp, daysLater, TimeZone.getDefault(), Locale.getDefault());
    }

    public static Timestamp getDayStart(Timestamp stamp, TimeZone timeZone, Locale locale) {
        return getDayStart(stamp, 0, timeZone, locale);
    }

    public static Timestamp getDayStart(Timestamp stamp, int daysLater, TimeZone timeZone, Locale locale) {
        Calendar tempCal = toCalendar(stamp, timeZone, locale);
        tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0,
                0, 0);
        tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
        Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
        retStamp.setNanos(0);
        return retStamp;
    }

    public static java.util.Calendar toCalendar(java.sql.Timestamp stamp) {
        Calendar cal = Calendar.getInstance();
        if (stamp != null) {
            cal.setTimeInMillis(stamp.getTime());
        }
        return cal;
    }

    /**
     * Returns a Calendar object initialized to the specified date/time, time
     * zone, and locale.
     *
     * @param date
     *            date/time to use
     * @param timeZone
     * @param locale
     * @return Calendar object
     * @see java.util.Calendar
     */
    public static Calendar toCalendar(Date date, TimeZone timeZone, Locale locale) {
        Calendar cal = Calendar.getInstance(timeZone, locale);
        if (date != null) {
            cal.setTime(date);
        }
        return cal;
    }
}

Related

  1. getMonthStart(java.sql.Timestamp stamp)
  2. getMonthStartTimestamp(Date date)
  3. getNanos(Timestamp timestamp)
  4. getNanoString(Timestamp timestamp, boolean full, char nanoSep)
  5. getNbHours(Timestamp dateA, Timestamp dateB)
  6. getNextTimestamp(Timestamp previous, long nrDays)
  7. getNotNullTimestampValue(String timestamp, String format)
  8. getNowTimestamp()
  9. getNowTimeStamp()