// ------------------ // Extract parameters // ------------------ int year; int month; int day; int hour; int minute; int second; intdeci_sec=0; intoffset=0; year = (bytes[0] * 256) + bytes[1]; month = bytes[2]; day = bytes[3]; hour = bytes[4]; minute = bytes[5]; second = bytes[6]; if (bytes.length >= 8) deci_sec = bytes[7]; if (bytes.length >= 10) { offset = bytes[9] * 60; if (bytes.length >= 11) offset += bytes[10]; if (bytes[8] == '-') offset = -offset; offset *= 60 * 1000; }
// ------------------------------------ // Get current DST and time zone offset // ------------------------------------ Calendar calendar; int my_dst; int my_zone; calendar = Calendar.getInstance(); my_dst = calendar.get(Calendar.DST_OFFSET); my_zone = calendar.get(Calendar.ZONE_OFFSET);
// ---------------------------------- // Compose result // Month to be converted into 0-based // ---------------------------------- calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, deci_sec * 100);
// ----------------------------------------------------------------------------------- // If the offset is set, we have to convert the time using the offset of // our time zone // ----------------------------------------------------------------------------------- if (offset != 0) { int delta; delta = my_zone - offset; calendar.add(Calendar.MILLISECOND, delta); }
// ------------- // Return result // ------------- return (calendar.getTime());