Search in sources :

Example 96 with SimpleTimeZone

use of java.util.SimpleTimeZone in project OpenAM by OpenRock.

the class AgentBase method getLocalDateAsGMTString.

protected String getLocalDateAsGMTString() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
    dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
    Date date = new Date();
    return dateFormat.format(date);
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 97 with SimpleTimeZone

use of java.util.SimpleTimeZone in project XobotOS by xamarin.

the class SimpleDateFormat method parseTimeZone.

private int parseTimeZone(String string, int offset) {
    boolean foundGMT = string.regionMatches(offset, "GMT", 0, 3);
    if (foundGMT) {
        offset += 3;
    }
    char sign;
    if (offset < string.length() && ((sign = string.charAt(offset)) == '+' || sign == '-')) {
        ParsePosition position = new ParsePosition(offset + 1);
        Number result = numberFormat.parse(string, position);
        if (result == null) {
            return -position.getErrorIndex() - 1;
        }
        int hour = result.intValue();
        int raw = hour * 3600000;
        int index = position.getIndex();
        if (index < string.length() && string.charAt(index) == ':') {
            position.setIndex(index + 1);
            result = numberFormat.parse(string, position);
            if (result == null) {
                return -position.getErrorIndex() - 1;
            }
            int minute = result.intValue();
            raw += minute * 60000;
        } else if (hour >= 24) {
            raw = (hour / 100 * 3600000) + (hour % 100 * 60000);
        }
        if (sign == '-') {
            raw = -raw;
        }
        calendar.setTimeZone(new SimpleTimeZone(raw, ""));
        return position.getIndex();
    }
    if (foundGMT) {
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        return offset;
    }
    String[][] zones = formatData.internalZoneStrings();
    for (String[] element : zones) {
        for (int j = TimeZones.LONG_NAME; j < TimeZones.NAME_COUNT; j++) {
            if (string.regionMatches(true, offset, element[j], 0, element[j].length())) {
                TimeZone zone = TimeZone.getTimeZone(element[TimeZones.OLSON_NAME]);
                if (zone == null) {
                    return -offset - 1;
                }
                int raw = zone.getRawOffset();
                if (j == TimeZones.LONG_NAME_DST || j == TimeZones.SHORT_NAME_DST) {
                    /*
                         * TODO, http://b/4723412
                         * We can't use TimeZone#getDSTSavings here because that
                         * will return 0 if the zone no longer uses DST. We
                         * should change this to use TimeZone.getOffset(long),
                         * which requires the complete date to be parsed first.
                         */
                    raw += 3600000;
                }
                calendar.setTimeZone(new SimpleTimeZone(raw, ""));
                return offset + element[j].length();
            }
        }
    }
    return -offset - 1;
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 98 with SimpleTimeZone

use of java.util.SimpleTimeZone in project jdbc-shards by wplatform.

the class BaseTestCase method assertEquals.

/**
     * Check if two values are equal, and if not throw an exception.
     *
     * @param expected the expected value
     * @param actual the actual value
     * @throws AssertionError if the values are not equal
     */
public void assertEquals(java.util.Date expected, java.util.Date actual) {
    if (expected != actual && !expected.equals(actual)) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        SimpleTimeZone gmt = new SimpleTimeZone(0, "Z");
        df.setTimeZone(gmt);
        fail("Expected: " + df.format(expected) + " actual: " + df.format(actual));
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 99 with SimpleTimeZone

use of java.util.SimpleTimeZone in project XobotOS by xamarin.

the class DERUTCTime method getAdjustedDate.

/**
     * return the time as an adjusted date
     * in the range of 1950 - 2049.
     *
     * @return a date in the range of 1950 to 2049.
     * @exception ParseException if the date string cannot be parsed.
     */
public Date getAdjustedDate() throws ParseException {
    SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
    dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
    return dateF.parse(getAdjustedTime());
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

Example 100 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDate_Basics method testToDate_springDST.

public void testToDate_springDST() {
    LocalDate base = new LocalDate(2007, 4, 2);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 4, 2);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

Aggregations

SimpleTimeZone (java.util.SimpleTimeZone)114 TimeZone (java.util.TimeZone)42 GregorianCalendar (java.util.GregorianCalendar)34 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)20 Calendar (java.util.Calendar)8 Test (org.junit.Test)7 BasicDBObject (com.mongodb.BasicDBObject)3 BSONTimestamp (org.bson.types.BSONTimestamp)3 Code (org.bson.types.Code)3 CodeWScope (org.bson.types.CodeWScope)3 ObjectId (org.bson.types.ObjectId)3 Support_TimeZone (tests.support.Support_TimeZone)3 DBRef (com.mongodb.DBRef)2 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 DateFormat (java.text.DateFormat)2 ParsePosition (java.text.ParsePosition)2 Binary (org.bson.types.Binary)2 MaxKey (org.bson.types.MaxKey)2