Search in sources :

Example 46 with SimpleTimeZone

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

the class TestLocalDateTime_Basics method testToDate_autumnDST_Zone.

public void testToDate_autumnDST_Zone() {
    LocalDateTime base = new LocalDateTime(2007, 10, 2, 0, 20, 30, 0);
    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(TimeZone.getDefault());
        check(base, 2007, 10, 2, 0, 20, 30, 0);
        assertEquals("Tue Oct 02 00:20:30 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)

Example 47 with SimpleTimeZone

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

the class TestLocalDateTime_Basics method testToDate_springDST_Zone.

public void testToDate_springDST_Zone() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    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(TimeZone.getDefault());
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        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)

Example 48 with SimpleTimeZone

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

the class TestLocalDate_Basics method testToDate_autumnDST.

public void testToDate_autumnDST() {
    LocalDate base = new LocalDate(2007, 10, 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, 10, 2);
        assertEquals("Tue Oct 02 00: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)

Example 49 with SimpleTimeZone

use of java.util.SimpleTimeZone in project fc-java-sdk by aliyun.

the class ParameterHelper method parseISO8601.

public static Date parseISO8601(String strDate) throws ParseException {
    if (null == strDate || "".equals(strDate)) {
        return null;
    }
    SimpleDateFormat df = new SimpleDateFormat(FORMAT_ISO8601);
    df.setTimeZone(new SimpleTimeZone(0, TIME_ZONE));
    return df.parse(strDate);
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

Example 50 with SimpleTimeZone

use of java.util.SimpleTimeZone in project jdk8u_jdk by JetBrains.

the class SimpleDateFormat method readObject.

/**
     * After reading an object from the input stream, the format
     * pattern in the object is verified.
     * <p>
     * @exception InvalidObjectException if the pattern is invalid
     */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    try {
        compiledPattern = compile(pattern);
    } catch (Exception e) {
        throw new InvalidObjectException("invalid pattern");
    }
    if (serialVersionOnStream < 1) {
        // didn't have defaultCenturyStart field
        initializeDefaultCentury();
    } else {
        // fill in dependent transient field
        parseAmbiguousDatesAsAfter(defaultCenturyStart);
    }
    serialVersionOnStream = currentSerialVersion;
    // If the deserialized object has a SimpleTimeZone, try
    // to replace it with a ZoneInfo equivalent in order to
    // be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    TimeZone tz = getTimeZone();
    if (tz instanceof SimpleTimeZone) {
        String id = tz.getID();
        TimeZone zi = TimeZone.getTimeZone(id);
        if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
            setTimeZone(zi);
        }
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) InvalidObjectException(java.io.InvalidObjectException) IOException(java.io.IOException) InvalidObjectException(java.io.InvalidObjectException)

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