Java 8 SimpleTimeZone - 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 SimpleTimeZone class.

This code example shows how to use the following methods:clone, inDaylightTime, setStartYear
        assertFalse("Reykjavik doesn't use DST", atlanticReykjavik.useDaylightTime());
    } 
 
    // http://code.google.com/p/android/issues/detail?id=11542 
    public void test_clone_SimpleTimeZone() { 
        SimpleTimeZone stz = new SimpleTimeZone(21600000, "Central Standard Time");
        stz.setStartYear(1000);
        stz.inDaylightTime(new Date());
        stz.clone();
    } 
 
    // http://b/3049014 
    public void testCustomTimeZoneDisplayNames() { 
        TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
        TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
        TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
        assertEquals("GMT+00:01", tz0001.getDisplayName(false, TimeZone.SHORT, Locale.US));
        assertEquals("GMT+01:30", tz0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
        assertEquals("GMT-01:30", tzMinus0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
    } 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
                o = format.parse(b.get("$date").toString(), new ParsePosition(0));
 
                if (o == null) {
                    // try older format with no ms 
                    format = new SimpleDateFormat(_secDateFormat);
                    format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
                    o = format.parse(b.get("$date").toString(), new ParsePosition(0));
                } 
            } 
        } else if (b.containsField("$regex")) {
            o = Pattern.compile((String) b.get("$regex"),
                    BSON.regexFlags((String) b.get("$options")));
        } else if (b.containsField("$ts")) { //Legacy timestamp format
            Integer ts = ((Number) b.get("$ts")).intValue();
            Integer inc = ((Number) b.get("$inc")).intValue();
            o = new BSONTimestamp(ts, inc);
        } else if (b.containsField("$timestamp")) {
            BSONObject tsObject = (BSONObject) b.get("$timestamp");
            Integer ts = ((Number) tsObject.get("t")).intValue();
            Integer inc = ((Number) tsObject.get("i")).intValue();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:clone, inDaylightTime, setStartYear
        assertFalse("Reykjavik doesn't use DST", atlanticReykjavik.useDaylightTime());
    } 
 
    // http://code.google.com/p/android/issues/detail?id=11542 
    public void test_clone_SimpleTimeZone() { 
        SimpleTimeZone stz = new SimpleTimeZone(21600000, "Central Standard Time");
        stz.setStartYear(1000);
        stz.inDaylightTime(new Date());
        stz.clone();
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:inDaylightTime, setEndRule, setStartRule, useDaylightTime
	 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int, boolean) 
	 */ 
	public void test_setEndRuleIIIIZ() { 
		// Test for method void java.util.SimpleTimeZone.setEndRule(int, int, 
		// int, int, boolean) 
        SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
		// Spec indicates that both end and start must be set or result is 
		// undefined 
		st.setStartRule(Calendar.NOVEMBER, 8, Calendar.SUNDAY, 1, false);
		st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, true);
		assertTrue("StartRule improperly set1", st.useDaylightTime());
		assertTrue("StartRule improperly set2", st
				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
						7, 12, 0).getTime())));
		assertTrue("StartRule improperly set3", st
				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
						20, 12, 0).getTime())));
		assertTrue("StartRule improperly set4", !(st
				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
						6, 12, 0).getTime())));

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
   @Test 
   public void testDate() { 
       Date d = new Date();
       SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
       format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
       String formattedDate = format.format(d);
 
       String serialized = JSON.serialize(d);
       assertEquals("{ \"$date\" : \"" + formattedDate + "\"}", serialized);
 
       Date d2 = (Date)JSON.parse(serialized);
       assertEquals(d.toString(), d2.toString());
       assertTrue(d.equals(d2));
   } 
 
    @Test 
    public void testJSONEncoding() throws ParseException { 
        String json = "{ 'str' : 'asdfasd' , 'long' : 123123123123 , 'int' : 5 , 'float' : 0.4 , 'bool' : false , 'date' : { '$date' : '2011-05-18T18:56:00Z'} , 'pat' : { '$regex' : '.*' , '$options' : ''} , 'oid' : { '$oid' : '4d83ab3ea39562db9c1ae2ae'} , 'ref' : { '$ref' : 'test.test' , '$id' : { '$oid' : '4d83ab59a39562db9c1ae2af'}} , 'code' : { '$code' : 'asdfdsa'} , 'codews' : { '$code' : 'ggggg' , '$scope' : { }} , 'ts' : { '$ts' : 1300474885 , '$inc' : 10} , 'null' :  null, 'uuid' : { '$uuid' : '60f65152-6d4a-4f11-9c9b-590b575da7b5' }}";
        BasicDBObject a = (BasicDBObject) JSON.parse(json);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    public void testFormattingTimezones() { 
        FormatTester test = new FormatTester();
        Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
 
        TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
        TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
        TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
 
        format.setTimeZone(tz0001);
        test.test(" Z", cal, " +0001", DateFormat.TIMEZONE_FIELD);
        test.test(" ZZZZ", cal, " +0001", DateFormat.TIMEZONE_FIELD);
        format.setTimeZone(tz0130);
        test.test(" Z", cal, " +0130", DateFormat.TIMEZONE_FIELD);
        format.setTimeZone(tzMinus0130);
        test.test(" Z", cal, " -0130", DateFormat.TIMEZONE_FIELD);
 
        format.setTimeZone(tz0001);
        test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
        test.test(" zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDSTSavings, getRawOffset, inDaylightTime, useDaylightTime
     *        int, int, int, int, int, int, int, int, int) 
     */ 
    public void test_ConstructorILjava_lang_StringIIIIIIIII() { 
        // Test for method java.util.SimpleTimeZone(int, java.lang.String, int, 
        // int, int, int, int, int, int, int, int) 
        SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
                1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
                0, 1000 * 60 * 60); 
        assertTrue("Incorrect TZ constructed", st
                .inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
                        13).getTime()));
        assertTrue("Incorrect TZ constructed", !(st
                .inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
                        13).getTime())));
        assertEquals("Incorrect TZ constructed", "TEST", st.getID());
        assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
        assertTrue("Incorrect TZ constructed", st.useDaylightTime());
        assertTrue("Incorrect TZ constructed",
                st.getDSTSavings() == 1000 * 60 * 60);
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
     * is used. 
     */ 
    public Time( 
        Date    date)
    { 
        SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
        SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");
 
        dateF.setTimeZone(tz);
 
        String  d = dateF.format(date) + "Z";
        int     year = Integer.parseInt(d.substring(0, 4));
 
        if (year < 1950 || year > 2049)
        { 
            time = new DERGeneralizedTime(d);
        } 
        else 
        { 
            time = new DERUTCTime(d.substring(2));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
     * is used. 
     */ 
    public Time( 
        Date    date)
    { 
        SimpleTimeZone      tz = new SimpleTimeZone(0, "Z");
        SimpleDateFormat    dateF = new SimpleDateFormat("yyyyMMddHHmmss");
 
        dateF.setTimeZone(tz);
 
        String  d = dateF.format(date) + "Z";
        int     year = Integer.parseInt(d.substring(0, 4));
 
        if (year < 1950 || year > 2049)
        { 
            time = new DERGeneralizedTime(d);
        } 
        else 
        { 
            time = new DERUTCTime(d.substring(2));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private final MifosCurrency currency;
    private final TimeZone timeZone;
 
    public SystemConfiguration(MifosCurrency currency, int timeZoneOffSet) {
        this.currency = currency;
        this.timeZone = new SimpleTimeZone(timeZoneOffSet, SimpleTimeZone.getAvailableIDs(timeZoneOffSet)[0]);
    } 
 
    public MifosCurrency getCurrency() { 
        return currency;
    } 
 
    public TimeZone getMifosTimeZone() {
        return timeZone;
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 SimpleTimeZone Methods: