java.util.SimpleTimeZone Java Examples
The following examples show how to use
java.util.SimpleTimeZone.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Time.java From RipplePower with Apache License 2.0 | 7 votes |
/** * Creates a time object from a given date - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. * * @param time a date object representing the time of interest. */ public Time( Date time) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss"); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
Example #2
Source File: Time.java From RipplePower with Apache License 2.0 | 6 votes |
/** * Creates a time object from a given date and locale - if the date is between 1950 * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime * is used. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the GeneralizedTime produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public Time( Date time, Locale locale) { SimpleTimeZone tz = new SimpleTimeZone(0, "Z"); SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss", locale); dateF.setTimeZone(tz); String d = dateF.format(time) + "Z"; int year = Integer.parseInt(d.substring(0, 4)); if (year < 1950 || year > 2049) { this.time = new DERGeneralizedTime(d); } else { this.time = new DERUTCTime(d.substring(2)); } }
Example #3
Source File: TestDateTimeFormatStyle.java From astor with GNU General Public License v2.0 | 6 votes |
public void testForStyle_shortTime() throws Exception { DateTimeFormatter f = DateTimeFormat.shortTime(); DateTimeFormatter g = DateTimeFormat.forStyle("-S"); assertSame(g, f); DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 0); String expect = DateFormat.getTimeInstance(DateFormat.SHORT, UK).format(dt.toDate()); assertEquals(expect, f.print(dt)); expect = DateFormat.getTimeInstance(DateFormat.SHORT, US).format(dt.toDate()); assertEquals(expect, f.withLocale(US).print(dt)); expect = DateFormat.getTimeInstance(DateFormat.SHORT, FRANCE).format(dt.toDate()); assertEquals(expect, f.withLocale(FRANCE).print(dt)); if (TimeZone.getDefault() instanceof SimpleTimeZone) { // skip test, as it needs historical time zone info } else { DateTime date = new DateTime( DateFormat.getTimeInstance(DateFormat.SHORT, FRANCE).parse(expect)); assertEquals(date, f.withLocale(FRANCE).parseDateTime(expect)); } }
Example #4
Source File: ListeFilme.java From MLib with GNU General Public License v3.0 | 6 votes |
/** * Get the age of the film list. * * @return Age as a {@link java.util.Date} object. */ public Date getAgeAsDate() { String date; if (!metaDaten[ListeFilme.FILMLISTE_DATUM_GMT_NR].isEmpty()) { date = metaDaten[ListeFilme.FILMLISTE_DATUM_GMT_NR]; sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); } else { date = metaDaten[ListeFilme.FILMLISTE_DATUM_NR]; } Date filmDate = null; try { filmDate = sdf.parse(date); } catch (ParseException ignored) { } return filmDate; }
Example #5
Source File: SegmentedTimeline.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Returns the milliseconds for midnight of the first Monday after * 1-Jan-1900, ignoring daylight savings. * * @return The milliseconds. * * @since 1.0.7 */ public static long firstMondayAfter1900() { int offset = TimeZone.getDefault().getRawOffset(); TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset); // calculate midnight of first monday after 1/1/1900 relative to // current locale Calendar cal = new GregorianCalendar(z); cal.set(1900, 0, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { cal.add(Calendar.DATE, 1); } //return cal.getTimeInMillis(); // preceding code won't work with JDK 1.3 return cal.getTime().getTime(); }
Example #6
Source File: StorableTimeFenceTest.java From JCVD with MIT License | 6 votes |
@Test public void testEquals() { StorableTimeFence fence1 = StorableTimeFence.inInterval(2, 300); StorableTimeFence fence2 = StorableTimeFence.inInterval(2, 400); StorableTimeFence fence3 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300); StorableTimeFence fence4 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300); StorableTimeFence fence5 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, new SimpleTimeZone(3, "1"), 20, 400); StorableTimeFence fence6 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1); StorableTimeFence fence7 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1); StorableTimeFence fence8 = StorableTimeFence.inTimeInterval(TIME_INTERVAL_AFTERNOON); StorableTimeFence fence9 = StorableTimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_WEEKDAY); assertThat(fence1.equals(fence1), is(true)); assertThat(fence3.equals(fence4), is(true)); assertThat(fence2.equals(null), is(false)); assertThat(fence4.equals(fence5), is(false)); assertThat(fence5.equals(fence6), is(false)); assertThat(fence6.equals(fence7), is(true)); assertThat(fence8.equals(fence9), is(false)); }
Example #7
Source File: TestZoneId.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(expectedExceptions = DateTimeException.class) public void test_systemDefault_unableToConvert_badFormat() { TimeZone current = TimeZone.getDefault(); try { TimeZone.setDefault(new SimpleTimeZone(127, "Something Weird")); ZoneId.systemDefault(); } finally { TimeZone.setDefault(current); } }
Example #8
Source File: DateConverter.java From sambox with Apache License 2.0 | 5 votes |
static String formatTZoffset(long millis, String sep) { SimpleDateFormat sdf = new SimpleDateFormat("Z"); // #hhmm sdf.setTimeZone(new SimpleTimeZone(restrainTZoffset(millis), "unknown")); String tz = sdf.format(new Date()); return tz.substring(0, 3) + sep + tz.substring(3); }
Example #9
Source File: ZoneInfoOld.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object representing the last GMT * offset and DST schedule or null if this time zone doesn't * observe DST. */ synchronized SimpleTimeZone getLastRule() { if (lastRule == null) { lastRule = getLastRuleInstance(); } return lastRule; }
Example #10
Source File: ZoneInfo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Queries if the specified date is in Daylight Saving Time. */ public boolean inDaylightTime(Date date) { if (date == null) { throw new NullPointerException(); } if (transitions == null) { return false; } long utc = date.getTime() - rawOffsetDiff; int index = getTransitionIndex(utc, UTC_TIME); // before transitions in the transition table if (index < 0) { return false; } // the time is in the table range. if (index < transitions.length) { return (transitions[index] & DST_MASK) != 0; } // beyond the transition table SimpleTimeZone tz = getLastRule(); if (tz != null) { return tz.inDaylightTime(date); } return false; }
Example #11
Source File: Proxy.java From odo with Apache License 2.0 | 5 votes |
/** * Log modified request * * @param httpMethodProxyRequest * @param httpServletResponse * @param history */ private void logRequestHistory(HttpMethod httpMethodProxyRequest, PluginResponse httpServletResponse, History history) { try { if (requestInformation.get().handle && requestInformation.get().client.getIsActive()) { logger.info("Storing history"); String createdDate; SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); sdf.applyPattern("dd MMM yyyy HH:mm:ss"); createdDate = sdf.format(new Date()) + " GMT"; history.setCreatedAt(createdDate); history.setRequestURL(HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString())); history.setRequestParams(httpMethodProxyRequest.getQueryString() == null ? "" : httpMethodProxyRequest.getQueryString()); history.setRequestHeaders(HttpUtilities.getHeaders(httpMethodProxyRequest)); history.setResponseHeaders(HttpUtilities.getHeaders(httpServletResponse)); history.setResponseCode(Integer.toString(httpServletResponse.getStatus())); history.setResponseContentType(httpServletResponse.getContentType()); history.setResponseData(httpServletResponse.getContentString()); history.setResponseBodyDecoded(httpServletResponse.isContentDecoded()); HistoryService.getInstance().addHistory(history); logger.info("Done storing"); } } catch (URIException e) { e.printStackTrace(); } }
Example #12
Source File: JulianDateTest.java From solarpositioning with MIT License | 5 votes |
@Test public void testWithTimeZone() { GregorianCalendar time = new GregorianCalendar(new SimpleTimeZone(-7 * 60 * 60 * 1000, "LST")); time.set(2003, Calendar.OCTOBER, 17, 12, 30, 30); // 17 October 2003, 12:30:30-07:00 JulianDate julDate = new JulianDate(time); assertEquals(2452930.312847222, julDate.getJulianDate(), TOLERANCE); }
Example #13
Source File: ZoneInfoOld.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object representing the last GMT * offset and DST schedule or null if this time zone doesn't * observe DST. */ synchronized SimpleTimeZone getLastRule() { if (lastRule == null) { lastRule = getLastRuleInstance(); } return lastRule; }
Example #14
Source File: PackedDate.java From RipplePower with Apache License 2.0 | 5 votes |
/** * Base constructor from a java.util.date object. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the PackedDate produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public PackedDate( Date time, Locale locale) { SimpleDateFormat dateF = new SimpleDateFormat("yyMMdd'Z'", locale); dateF.setTimeZone(new SimpleTimeZone(0,"Z")); this.time = convert(dateF.format(time)); }
Example #15
Source File: ZoneInfo.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object that represents the last * known daylight saving time rules. * * @return a SimpleTimeZone object or null if this time zone * doesn't observe DST. */ public SimpleTimeZone getLastRuleInstance() { if (simpleTimeZoneParams == null) { return null; } if (simpleTimeZoneParams.length == 10) { return new SimpleTimeZone(getLastRawOffset(), getID(), simpleTimeZoneParams[0], simpleTimeZoneParams[1], simpleTimeZoneParams[2], simpleTimeZoneParams[3], simpleTimeZoneParams[4], simpleTimeZoneParams[5], simpleTimeZoneParams[6], simpleTimeZoneParams[7], simpleTimeZoneParams[8], simpleTimeZoneParams[9], dstSavings); } return new SimpleTimeZone(getLastRawOffset(), getID(), simpleTimeZoneParams[0], simpleTimeZoneParams[1], simpleTimeZoneParams[2], simpleTimeZoneParams[3], simpleTimeZoneParams[4], simpleTimeZoneParams[5], simpleTimeZoneParams[6], simpleTimeZoneParams[7], dstSavings); }
Example #16
Source File: DERGeneralizedTime.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
/** * base constructer from a java.util.date object */ public DERGeneralizedTime( Date time) { SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'"); dateF.setTimeZone(new SimpleTimeZone(0,"Z")); this.time = dateF.format(time); }
Example #17
Source File: TestZoneId.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions = DateTimeException.class) public void test_systemDefault_unableToConvert_badFormat() { TimeZone current = TimeZone.getDefault(); try { TimeZone.setDefault(new SimpleTimeZone(127, "Something Weird")); ZoneId.systemDefault(); } finally { TimeZone.setDefault(current); } }
Example #18
Source File: ZoneInfoOld.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object representing the last GMT * offset and DST schedule or null if this time zone doesn't * observe DST. */ synchronized SimpleTimeZone getLastRule() { if (lastRule == null) { lastRule = getLastRuleInstance(); } return lastRule; }
Example #19
Source File: ASN1UTCTime.java From RipplePower with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #20
Source File: SimpleTimeZoneTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String) */ public void test_ConstructorILjava_lang_String() { // Test for method java.util.SimpleTimeZone(int, java.lang.String) SimpleTimeZone st = new SimpleTimeZone(1000, "TEST"); assertEquals("Incorrect TZ constructed", "TEST", st.getID()); assertTrue("Incorrect TZ constructed: " + "returned wrong offset", st .getRawOffset() == 1000); assertTrue("Incorrect TZ constructed" + "using daylight savings", !st .useDaylightTime()); }
Example #21
Source File: TestZoneId.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions = DateTimeException.class) public void test_systemDefault_unableToConvert_badFormat() { TimeZone current = TimeZone.getDefault(); try { TimeZone.setDefault(new SimpleTimeZone(127, "Something Weird")); ZoneId.systemDefault(); } finally { TimeZone.setDefault(current); } }
Example #22
Source File: ZoneInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object that represents the last * known daylight saving time rules. * * @return a SimpleTimeZone object or null if this time zone * doesn't observe DST. */ public SimpleTimeZone getLastRuleInstance() { if (simpleTimeZoneParams == null) { return null; } if (simpleTimeZoneParams.length == 10) { return new SimpleTimeZone(getLastRawOffset(), getID(), simpleTimeZoneParams[0], simpleTimeZoneParams[1], simpleTimeZoneParams[2], simpleTimeZoneParams[3], simpleTimeZoneParams[4], simpleTimeZoneParams[5], simpleTimeZoneParams[6], simpleTimeZoneParams[7], simpleTimeZoneParams[8], simpleTimeZoneParams[9], dstSavings); } return new SimpleTimeZone(getLastRawOffset(), getID(), simpleTimeZoneParams[0], simpleTimeZoneParams[1], simpleTimeZoneParams[2], simpleTimeZoneParams[3], simpleTimeZoneParams[4], simpleTimeZoneParams[5], simpleTimeZoneParams[6], simpleTimeZoneParams[7], dstSavings); }
Example #23
Source File: DateUtilsTest.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
@Test public void formatIso8601Date() throws ParseException { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); String expected = sdf.format(date); String actual = DateUtils.formatISO8601Date(date); assertEquals(expected, actual); Date expectedDate = sdf.parse(expected); Date actualDate = DateUtils.parseISO8601Date(actual); assertEquals(expectedDate, actualDate); }
Example #24
Source File: PackedDate.java From ripple-lib-java with ISC License | 5 votes |
/** * Base constructor from a java.util.date object. You may need to use this constructor if the default locale * doesn't use a Gregorian calender so that the PackedDate produced is compatible with other ASN.1 implementations. * * @param time a date object representing the time of interest. * @param locale an appropriate Locale for producing an ASN.1 GeneralizedTime value. */ public PackedDate( Date time, Locale locale) { SimpleDateFormat dateF = new SimpleDateFormat("yyMMdd'Z'", locale); dateF.setTimeZone(new SimpleTimeZone(0,"Z")); this.time = convert(dateF.format(time)); }
Example #25
Source File: SimpleTimeZoneTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testDstParis2014_LastSundayMarch_LastSundayOctober_UtcTime() { TimeZone timeZone = new SimpleTimeZone(PARIS_RAW_OFFSET, "Europe/Paris", Calendar.MARCH, -1, Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME, Calendar.OCTOBER, -1, Calendar.SUNDAY, 3600000, SimpleTimeZone.UTC_TIME, 3600000); checkDstParis2014(timeZone); }
Example #26
Source File: TestPropertyListParser.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testParseDate() throws Exception { final Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2002); calendar.set(Calendar.MONTH, Calendar.MARCH); calendar.set(Calendar.DAY_OF_MONTH, 22); calendar.set(Calendar.HOUR_OF_DAY, 11); calendar.set(Calendar.MINUTE, 30); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.setTimeZone(new SimpleTimeZone(60 * 60 * 1000, "Apache/Jakarta")); assertEquals("parsed date", calendar.getTime(), parser.parseDate("<*D2002-03-22 11:30:00 +0100>")); }
Example #27
Source File: DateUtil.java From mq-http-java-sdk with MIT License | 5 votes |
private static DateFormat getAlternativeIso8601DateFormat() { SimpleDateFormat df = new SimpleDateFormat(ALTERNATIVE_ISO8601_DATE_FORMAT, Locale.US); df.setTimeZone(new SimpleTimeZone(0, "GMT")); return df; }
Example #28
Source File: DateUtil.java From mq-http-java-sdk with MIT License | 5 votes |
private static DateFormat getIso8601DateFormat() { SimpleDateFormat df = new SimpleDateFormat(ISO8601_DATE_FORMAT, Locale.US); df.setTimeZone(new SimpleTimeZone(0, "GMT")); return df; }
Example #29
Source File: ZoneInfoOld.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns a SimpleTimeZone object representing the last GMT * offset and DST schedule or null if this time zone doesn't * observe DST. */ synchronized SimpleTimeZone getLastRule() { if (lastRule == null) { lastRule = getLastRuleInstance(); } return lastRule; }
Example #30
Source File: ASN1UTCTime.java From ripple-lib-java with ISC License | 5 votes |
/** * base constructor from a java.util.date object * @param time the Date to build the time from. */ public ASN1UTCTime( Date time) { SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmss'Z'"); dateF.setTimeZone(new SimpleTimeZone(0,"Z")); this.time = Strings.toByteArray(dateF.format(time)); }