Java TimeZone Add tomorrow(TimeZone zone)

Here you can find the source of tomorrow(TimeZone zone)

Description

tomorrow

License

Apache License

Declaration

public static Date tomorrow(TimeZone zone) 

Method Source Code


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

import static java.util.Calendar.*;

import java.util.*;

public class Main {
    public static Date tomorrow(int hour, int minute) {
        Calendar ca = truncate(Calendar.getInstance());
        ca.add(DATE, 1);//from   w w  w.j  a v  a  2s .  c  o m
        ca.set(HOUR_OF_DAY, hour);
        ca.set(MINUTE, minute);
        return ca.getTime();
    }

    public static Date tomorrow(TimeZone zone) {
        Calendar ca = truncate(Calendar.getInstance(zone));
        ca.add(DATE, 1);
        return ca.getTime();
    }

    /**
     * Truncate to begin of day: 0 hour 0 minute 0 second 0 millisecond
     * @param d The date to be truncated
     * @return the result truncated date
     */
    public static Date truncate(Date d) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(d);
        truncate(ca);
        return ca.getTime();
    }

    /**
     * Truncate to begin of day: 0 hour 0 minute 0 second 0 millisecond
     * @param d The date to be truncated
     * @return the result truncated date
     */
    public static Date truncate(Date d, TimeZone zone) {
        Calendar ca = Calendar.getInstance(zone);
        ca.setTime(d);
        truncate(ca);
        return ca.getTime();
    }

    /**
     * Truncate to begin of day: 0 hour 0 minute 0 second 0 millisecond
     * @param ca The calendar to be truncated
     */
    public static Calendar truncate(Calendar ca) {
        truncateHour(ca);
        ca.set(Calendar.HOUR_OF_DAY, 0);
        return ca;
    }

    public static void truncateHour(Calendar ca) {
        ca.set(Calendar.MILLISECOND, 0);
        ca.set(Calendar.SECOND, 0);
        ca.set(Calendar.MINUTE, 0);
    }
}

Related

  1. removeTimeZoneOffset(long t)
  2. shiftDate(Date date, TimeZone timeZone, String pattern)
  3. stringToCal(String s, TimeZone tz)
  4. stringToCalendar(String strDate, TimeZone timezone)
  5. toMidnight(long time, TimeZone tz)