Java 8 TimeZone - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TimeZone class.

This code example shows how to use the following methods:getOffset, inDaylightTime
        assertNonDaylightOffset(0, 157770000L, tz); // 1
        assertNonDaylightOffset(0, 157780000L, tz);
    } 
 
    private static void assertNonDaylightOffset(int expectedOffsetSeconds, long epochSeconds, TimeZone tz) {
        assertEquals(expectedOffsetSeconds * 1000, tz.getOffset(epochSeconds * 1000));
        assertFalse(tz.inDaylightTime(new Date(epochSeconds * 1000)));
    } 
 
    public void testZeroTransitionZones() throws Exception { 
        // Zones with no transitions historical or future seem ideal for testing. 
        String[] ids = new String[] { "Africa/Bujumbura", "Indian/Cocos", "Pacific/Wake", "UTC" };
        for (String id : ids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            assertFalse(tz.useDaylightTime());
            assertFalse(tz.inDaylightTime(new Date(Integer.MIN_VALUE)));
            assertFalse(tz.inDaylightTime(new Date(0)));
            assertFalse(tz.inDaylightTime(new Date(Integer.MAX_VALUE)));
            int currentOffset = tz.getOffset(new Date(0).getTime());
            assertEquals(currentOffset, tz.getOffset(new Date(Integer.MIN_VALUE).getTime()));
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getRawOffset
        else  
        { 
            _tzFormat=new SimpleDateFormat(_tzFormatString);
            _minFormat=new SimpleDateFormat(_minFormatString);
        } 
        _tzFormat.setTimeZone(tz);
        _minFormat.setTimeZone(tz);
        _lastSeconds=-1;
        _lastMinutes=-1;        
    } 
 
    /* ------------------------------------------------------------ */ 
    public TimeZone getTimeZone()
    { 
        return _tzFormat.getTimeZone();
    } 
     
    /* ------------------------------------------------------------ */ 
    /** Set the timezone. 
     * @param timeZoneId TimeZoneId the ID of the zone as used by 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDSTSavings, getID, getRawOffset
This code example shows how to use the following methods:toString, hasSameRules
                                      final TimeZone expected,
                                      final TimeZone actual) {
     
    if (null == expected && null == actual) return;
 
    assertNotNull(label + ": expected is null", expected);
    assertNotNull(label + ": actual is null", actual);
 
    final boolean same = expected.hasSameRules(actual);
 
    assertTrue(label + ": " + expected.toString() + " [[NOT SAME RULES]] " + 
               actual.toString(),
               same);
  } 
 
  public void testValidIds() throws Exception {
 
    final Set<String> idsTested = new HashSet<>();
 
    // brain dead: anything the JVM supports, should work 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDSTSavings, getRawOffset, inDaylightTime
 
		return jCalendar;
	} 
 
	public static int getTimeZoneOffset(TimeZone timeZone) {
		int offset = timeZone.getRawOffset();
 
		boolean inDaylightTime = timeZone.inDaylightTime(new Date());
 
		if (inDaylightTime) {
			offset += timeZone.getDSTSavings();
		} 
 
		return offset;
	} 
 
	public static int getWeekdayPosition(Calendar jCalendar) {
		int weekOfMonth = jCalendar.get(Calendar.WEEK_OF_MONTH);
 
		Calendar firstDayJCalendar = (Calendar)jCalendar.clone();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDisplayName, getRawOffset, useDaylightTime
	public TimeZoneOption(TimeZone timeZone, String timeZoneDisplayName)
	{ 
		this.timeZone = timeZone;
		this.timeZoneDisplayName = timeZoneDisplayName;
		 
		if (!timeZone.useDaylightTime())
		{ 
			String  shortName1 = timeZone.getDisplayName(false,TimeZone.SHORT);
			this.timeZoneTag = "("+shortName1+") ";
		} 
		else 
		{ 
			String  shortName1 = timeZone.getDisplayName(false,TimeZone.SHORT);
			String  shortName2 = timeZone.getDisplayName(true,TimeZone.SHORT);
			this.timeZoneTag = "("+shortName1+"/"+shortName2+") ";
		} 
		 
		// Get the number of hours from GMT 
		int rawOffset = timeZone.getRawOffset();
		gmtOffsetHours = rawOffset / (60*60*1000);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getDSTSavings, inDaylightTime, useDaylightTime
     * @param self a Date 
     * @return the DST offset as a Duration. 
     */ 
    public static Duration getDaylightSavingsOffset(Date self) {
        TimeZone timeZone = getTimeZone(self);
        int millis = (timeZone.useDaylightTime() && timeZone.inDaylightTime(self))
                ? timeZone.getDSTSavings() : 0;
        return new TimeDuration(0, 0, 0, millis);
    } 
 
    public static Duration getDaylightSavingsOffset(BaseDuration self) {
        return getDaylightSavingsOffset(new Date(self.toMilliseconds() + 1));
    } 
 
    /** 
     * Return a Duration representing the DST difference (if any) between two 
     * dates.  i.e. if one date is before the DST changeover, and the other 
     * date is after, the resulting duration will represent the DST offset. 
     * 
     * @param self  a Date 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getRawOffset
        else  
        { 
            _tzFormat=new SimpleDateFormat(_tzFormatString);
            _minFormat=new SimpleDateFormat(_minFormatString);
        } 
        _tzFormat.setTimeZone(tz);
        _minFormat.setTimeZone(tz);
        _lastSeconds=-1;
        _lastMinutes=-1;        
    } 
 
    /* ------------------------------------------------------------ */ 
    public TimeZone getTimeZone()
    { 
        return _tzFormat.getTimeZone();
    } 
     
    /* ------------------------------------------------------------ */ 
    /** Set the timezone. 
     * @param timeZoneId TimeZoneId the ID of the zone as used by 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getID
            Assert.fail(timeZoneDisplayName);
        } 
    } 
 
    private ScheduleExpression getTimezoneSpecificScheduleExpression() { 
        return new ScheduleExpression().timezone(this.timezone.getID());
    } 
 
    private boolean isLeapYear(Calendar cal) {
        int year = cal.get(Calendar.YEAR);
        return year % 4 == 0;
    } 
 
    private boolean isWeekDay(Calendar cal) {
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
 
        switch (dayOfWeek) {
            case Calendar.SATURDAY:
            case Calendar.SUNDAY:
                return false; 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getRawOffset
        else  
        { 
            _tzFormat=new SimpleDateFormat(_tzFormatString);
            _minFormat=new SimpleDateFormat(_minFormatString);
        } 
        _tzFormat.setTimeZone(tz);
        _minFormat.setTimeZone(tz);
        _lastSeconds=-1;
        _lastMinutes=-1;        
    } 
 
    /* ------------------------------------------------------------ */ 
    public TimeZone getTimeZone()
    { 
        return _tzFormat.getTimeZone();
    } 
     
    /* ------------------------------------------------------------ */ 
    /** Set the timezone. 
     * @param timeZoneId TimeZoneId the ID of the zone as used by 

6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 TimeZone Questions & Answers:

See Code Examples for Java 8 TimeZone Methods: