Java Code Examples for java.util.GregorianCalendar#getTimeZone()

The following examples show how to use java.util.GregorianCalendar#getTimeZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year}, {@code month}, {@code day}, {@code hour}, {@code minute} and {@code second}.
 * Uses the current date and time, sets the specified {@code year}, {@code month}, {@code day}, {@code hour}, {@code minute} and {@code second}, and returns the Date converted to a UTC timestamp.
 *
 * @param year   the year to represent
 * @param month  the month-of-year to represent, from 0 (January) to 11 (December)
 * @param day    the day-of-month to represent, from 1 to 31
 * @param hour   the hour-of-day to represent, from 0 to 23
 * @param minute the minute-of-hour to represent, from 0 to 59
 * @param second the second-of-hour to represent, from 0 to 59
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month, int day, int hour, int minute, int second) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    Assert.isTrue(1 <= day && day <= 31, "day param must be a value from 1 to 31");
    Assert.isTrue(0 <= hour && hour <= 23, "hour param must be a value from 1 to 23");
    Assert.isTrue(0 <= minute && minute <= 59, "minute param must be a value from 0 to 59");
    Assert.isTrue(0 <= second && second <= 59, "second param must be a value from 0 to 59");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 2
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year}, {@code month}, {@code day}, {@code hour}, {@code minute} and {@code second}.
 * Uses the current date and time, sets the specified {@code year}, {@code month}, {@code day}, {@code hour}, {@code minute} and {@code second}, and returns the Date converted to a UTC timestamp.
 *
 * @param year        the YEAR to represent
 * @param month       the MONTH to represent, from 0 (January) to 11 (December)
 * @param day         the DAY_OF_MONTH to represent, from 1 to 31
 * @param hour        the HOUR_OF_DAY to represent, from 0 to 23
 * @param minute      the MINUTE to represent, from 0 to 59
 * @param second      the SECOND to represent, from 0 to 59
 * @param millisecond the MILLISECOND to represent, from 0 to 59
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month, int day, int hour, int minute, int second, int millisecond) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    Assert.isTrue(1 <= day && day <= 31, "day param must be a value from 1 to 31");
    Assert.isTrue(0 <= hour && hour <= 23, "hour param must be a value from 1 to 23");
    Assert.isTrue(0 <= minute && minute <= 59, "minute param must be a value from 0 to 59");
    Assert.isTrue(0 <= second && second <= 59, "second param must be a value from 0 to 59");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millisecond);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 3
Source File: WcfDateSerializer.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(GregorianCalendar calendar) {
    StringBuilder sb = new StringBuilder("/Date(");
    sb.append(calendar.getTimeInMillis());
    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    if (offset != 0) {
        int minutes = Math.abs(offset / ONE_MINUTE);
        sb.append(offset > 0 ? "+" : "-").append(constraint(minutes / 60)).append(constraint(minutes % 60));
    }
    sb.append(")/");

    return sb.toString();
}
 
Example 4
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year} and {@code month}.
 * Uses the current date and time, sets the specified {@code year} and {@code month}, and returns the Date converted to a UTC timestamp.
 *
 * @param year  the year to represent
 * @param month the month-of-year to represent, from 0 (January) to 11 (December)
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 5
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year}, {@code month} and {@code day}
 * Uses the current date and time, sets the specified {@code year}, {@code month} and {@code day}, and returns the Date converted to a UTC timestamp.
 *
 * @param year  the year to represent
 * @param month the month-of-year to represent, from 0 (January) to 11 (December)
 * @param day   the day-of-month to represent, from 1 to 31
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month, int day) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    Assert.isTrue(1 <= day && day <= 31, "day param must be a value from 1 to 31");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 6
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year}, {@code month}, {@code day} and {@code hour}.
 * Uses the current date and time, sets the specified {@code year}, {@code month}, {@code day} and {@code hour}, and returns the Date converted to a UTC timestamp.
 *
 * @param year  the year to represent
 * @param month the month-of-year to represent, from 0 (January) to 11 (December)
 * @param day   the day-of-month to represent, from 1 to 31
 * @param hour  the hour-of-day to represent, from 0 to 23
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month, int day, int hour) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    Assert.isTrue(1 <= day && day <= 31, "day param must be a value from 1 to 31");
    Assert.isTrue(0 <= hour && hour <= 23, "hour param must be a value from 0 to 23");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 7
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} from the provided {@code year}, {@code month}, {@code day}, {@code hour} and {@code minute}.
 * Uses the current date and time, sets the specified {@code year}, {@code month}, {@code day}, {@code hour} and {@code minute}, and returns the Date converted to a UTC timestamp.
 *
 * @param year   the year to represent
 * @param month  the month-of-year to represent, from 0 (January) to 11 (December)
 * @param day    the day-of-month to represent, from 1 to 31
 * @param hour   the hour-of-day to represent, from 0 to 23
 * @param minute the minute-of-hour to represent, from 0 to 59
 * @return the UTC-based {@link Date}
 */
public static Date of(int year, int month, int day, int hour, int minute) {
    Assert.isTrue(0 <= month && month <= 11, "month param must be a value from 0 (January) to 11 (December)");
    Assert.isTrue(1 <= day && day <= 31, "day param must be a value from 1 to 31");
    Assert.isTrue(0 <= hour && hour <= 23, "hour param must be a value from 0 to 23");
    Assert.isTrue(0 <= minute && minute <= 59, "minute param must be a value from 0 to 59");
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}
 
Example 8
Source File: Instants.java    From okta-sdk-java with Apache License 2.0 3 votes vote down vote up
/**
 * Creates an UTC-based {@link Date} using the provided {@code year}.
 * Uses the current date and time, sets the specified {@code year} and returns the Date converted to a UTC timestamp.
 *
 * @param year the year to represent
 * @return the UTC-based {@link Date}
 */
public static Date of(int year) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    TimeZone fromTimeZone = cal.getTimeZone();
    return new Date(convertDate(cal.getTimeInMillis(), fromTimeZone, UTC_TIMEZONE));
}