Java Timestamp Field getWeekEnd(Timestamp stamp, TimeZone timeZone, Locale locale)

Here you can find the source of getWeekEnd(Timestamp stamp, TimeZone timeZone, Locale locale)

Description

get Week End

License

Apache License

Declaration

public static Timestamp getWeekEnd(Timestamp stamp, TimeZone timeZone, Locale locale) 

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 getWeekEnd(java.sql.Timestamp stamp) {
        return getWeekEnd(stamp, TimeZone.getDefault(), Locale.getDefault());
    }//from  ww  w . j a v  a2 s .co m

    public static Timestamp getWeekEnd(Timestamp stamp, 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.WEEK_OF_MONTH, 1);
        tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
        tempCal.add(Calendar.SECOND, -1);
        Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
        retStamp.setNanos(999999999);
        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. getstrTimestamp(String datetime)
  2. getSysDateTimestamp()
  3. getSystemTimestamp()
  4. getSystemTimestamp()
  5. getWeekEnd(Timestamp stamp, TimeZone timeZone, Locale locale)
  6. getWochentag(java.util.Locale locale, java.sql.Timestamp tDatum)
  7. getYearStart(Timestamp stamp, TimeZone timeZone, Locale locale)