/** * Get the month of a date. The first month of the year is JANUARY which is 0. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int monthOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.MONTH); }
/** * Get the day of month of a date. The first day of the month has value 1. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int dayMonthOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.DAY_OF_MONTH); }
/** * Whether the given date in the specified TimeZone is the first day of that * month. If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static boolean isBeginOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); return day == 1; } /**
/** * Given a date, a proper TimeZone, return the two month int. e.g. 1, 3, 5, 7, 9, 11. * If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static short twoMonthShort(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int month = (cal.get(Calendar.MONTH) / 2) * 2 + 1; return (short)month; }
/** * Get the month of a date. The first month of the year is JANUARY which is 1. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. */ public static final int monthOfDatePlus1(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.MONTH) + 1; }
/** * Whether the given date in the specified TimeZone is the last day of that * month. If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static boolean isEndOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return day == maxDay; }
/** * Get the year of a date. * @param when The date. * @param tz The time zone; if null, the current time zone is assumed. * @see #localizedYearOfDate */ public static final int yearOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. return cal.get(Calendar.YEAR); }
/** * Date Arithmetic function. Adds the specified (signed) amount of time to the given date, * based on the calendar's rules. * @param when The based date. * @param tz The time zone; if null, the current time zone is assumed. * @param field The time field. * @param amount The amount of date or time to be added to the field. */ public static final Date add(Date when, TimeZone tz, int field, int amount) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());//don't call cal.setTime(Date) which will reset the TimeZone. cal.add(field, amount); return cal.getTime(); }
private static SimpleDateFormat getDateFormat(TimeZone tzone) { SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd", Locales.getCurrent()); df.setTimeZone(tzone != null ? tzone : TimeZones.getCurrent()); return df; }
/** Returns the date format of the time only, * * <p>Default: it uses SimpleDateFormat to format the date. */ protected DateFormat getDateFormat(String fmt) { final DateFormat df = new SimpleDateFormat(fmt, _locale != null ? _locale : Locales.getCurrent()); final TimeZone tz = _tzone != null ? _tzone : TimeZones.getCurrent(); df.setTimeZone(tz); return df; }
/** * Given a date, a proper TimeZone, return the beginning date of the * month of the specified date and TimeZone. * If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static Date beginOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); cal.clear(); cal.set(year, month, 1); return cal.getTime(); }
private DateFormat getDateFormat() { final DateFormat df = new SimpleDateFormat("yyyy/MM/dd", Locales.getCurrent()); df.setTimeZone(TimeZones.getCurrent()); return df; }
private static SimpleDateFormat getLocalizedSimpleDateFormat(String formatPtn) { SimpleDateFormat sdf = new SimpleDateFormat(formatPtn, Locales.getCurrent()); sdf.setTimeZone(TimeZones.getCurrent()); return sdf; } }
private static SimpleDateFormat getLocalizedSimpleDateFormat(String formatPtn) { SimpleDateFormat sdf = new SimpleDateFormat(formatPtn, Locales.getCurrent()); sdf.setTimeZone(TimeZones.getCurrent()); return sdf; } }
/** * Given a date, a proper TimeZone, return the beginning date of * the specified date and TimeZone. If TimeZone is null, meaning use Default * TimeZone of the JVM. */ final public static Date beginOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());//don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); cal.clear(); cal.set(year, month, day); return cal.getTime(); }
/** * Given a date, a proper TimeZone, return the ending date of the * month of the specified date and TimeZone. * If TimeZone is null, meaning use default TimeZone of the JVM. */ final public static Date endOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); //don't call cal.setTime(Date) which will reset the TimeZone. final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); final int monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.clear(); cal.set(year, month, monthDays + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
/** * Given a date, a proper TimeZone, return the last millisecond date of * the specified date and TimeZone. If TimeZone is null, meaning use Default * TimeZone of the JVM. */ final public static Date endOfDate(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime());//don't call cal.setTime(Date) which will reset the TimeZone. final int day = cal.get(Calendar.DAY_OF_MONTH); final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); cal.clear(); cal.set(year, month, day + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
/** * Returns the date format of the specified format * * <p> * Default: it uses SimpleDateFormat to format the date. * * @param fmt * the pattern. */ protected DateFormat getDateFormat(String fmt) { final DateFormat df = new SimpleDateFormat(fmt, _locale != null ? _locale : Locales.getCurrent()); final TimeZone tz = _tzone != null ? _tzone : TimeZones.getCurrent(); df.setTimeZone(tz); return df; }
private static final DateFormat getDateFormat (String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) { if (locale == null) locale = Locales.getCurrent(); if (timezone == null) timezone = TimeZones.getCurrent(); pattern = getRealFormat(pattern, locale, dateStyle, timeStyle); final DateFormat df = new SimpleDateFormat(pattern, locale); df.setTimeZone(timezone); return df; } private static final String getRealFormat (String pattern, Locale locale, String dateStyle, String timeStyle) {
public ExecutionCarryOver(Desktop desktop) { _exec = Executions.getCurrent(); if (_exec == null || _exec.getDesktop() != desktop) throw new IllegalStateException("Wrong execution: " + _exec); _locale = Locales.getCurrent(); _timeZone = TimeZones.getCurrent(); }