java.util.TimeZone Java Examples
The following examples show how to use
java.util.TimeZone.
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: Arja_00134_s.java From coming with MIT License | 6 votes |
/** * {@inheritDoc} */ public void appendTo(StringBuffer buffer, Calendar calendar) { if (mTimeZoneForced) { if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(mDaylight); } else { buffer.append(mStandard); } } else { TimeZone timeZone = calendar.getTimeZone(); if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) { buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale)); } else { buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale)); } } }
Example #2
Source File: RequestContext.java From java-technology-stack with MIT License | 6 votes |
public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource, @Nullable RequestDataValueProcessor dataValueProcessor) { Assert.notNull(exchange, "ServerWebExchange is required"); Assert.notNull(model, "Model is required"); Assert.notNull(messageSource, "MessageSource is required"); this.exchange = exchange; this.model = model; this.messageSource = messageSource; LocaleContext localeContext = exchange.getLocaleContext(); Locale locale = localeContext.getLocale(); this.locale = (locale != null ? locale : Locale.getDefault()); TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ? ((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null); this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault()); this.defaultHtmlEscape = null; // TODO this.dataValueProcessor = dataValueProcessor; }
Example #3
Source File: UserFactory.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Gets the default time zone * @return US Eastern Time Zone */ public static RhnTimeZone getDefaultTimeZone() { RhnTimeZone sysDefault = getTimeZone(TimeZone.getDefault().getID()); if (sysDefault != null) { return sysDefault; } Session session = HibernateFactory.getSession(); List<RhnTimeZone> allTimeZones = session.getNamedQuery("RhnTimeZone.loadAll").list(); for (RhnTimeZone tz : allTimeZones) { if (TimeZone.getDefault().getRawOffset() == TimeZone.getTimeZone( tz.getOlsonName()).getRawOffset()) { return tz; } } // This should not happen unless the timezone table is incomplete return getTimeZone("America/New_York"); }
Example #4
Source File: MinuteTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Minute m = new Minute(59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); assertEquals(-623289660000L, m.getFirstMillisecond(zone)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((TimeZone) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
Example #5
Source File: ParseCEF.java From nifi with Apache License 2.0 | 6 votes |
@OnScheduled public void OnScheduled(final ProcessContext context) { // Configure jackson mapper before spawning onTriggers final SimpleModule module = new SimpleModule() .addSerializer(MacAddress.class, new MacAddressToStringSerializer()); mapper.registerModule(module); mapper.setDateFormat(this.simpleDateFormat); switch (context.getProperty(TIME_REPRESENTATION).getValue()) { case LOCAL_TZ: // set the mapper TZ to local TZ mapper.setTimeZone(TimeZone.getDefault()); tzId = TimeZone.getDefault().getID(); break; case UTC: // set the mapper TZ to local TZ mapper.setTimeZone(TimeZone.getTimeZone(UTC)); tzId = UTC; break; } }
Example #6
Source File: ZoneInfoOld.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns true if this zone has the same raw GMT offset value and * transition table as another zone info. If the specified * TimeZone object is not a ZoneInfoOld instance, this method returns * true if the specified TimeZone object has the same raw GMT * offset value with no daylight saving time. * * @param other the ZoneInfoOld object to be compared with * @return true if the given <code>TimeZone</code> has the same * GMT offset and transition information; false, otherwise. */ public boolean hasSameRules(TimeZone other) { if (this == other) { return true; } if (other == null) { return false; } if (!(other instanceof ZoneInfoOld)) { if (getRawOffset() != other.getRawOffset()) { return false; } // if both have the same raw offset and neither observes // DST, they have the same rule. if ((transitions == null) && (useDaylightTime() == false) && (other.useDaylightTime() == false)) { return true; } return false; } if (getLastRawOffset() != ((ZoneInfoOld)other).getLastRawOffset()) { return false; } return (checksum == ((ZoneInfoOld)other).checksum); }
Example #7
Source File: ComWorkflowStartStopReminderDaoImpl.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
@Override public ComReminder mapRow(ResultSet rs, int i) throws SQLException { ComReminder reminder = new ComReminderImpl(); reminder.setId(rs.getInt("reminder_id")); reminder.setCompanyId(rs.getInt("company_id")); reminder.setRecipientEmail(rs.getString("email")); reminder.setSenderName(getSenderName(rs.getString("sender_name"), rs.getString("sender_company_name"))); reminder.setMessage(rs.getString("message")); reminder.setSent(rs.getInt("notified") != 0); reminder.setLang(StringUtils.defaultIfEmpty(rs.getString("lang"), DEFAULT_LANGUAGE)); ReminderType reminderType = ReminderType.fromId(rs.getInt("type")); // No content generation available for unknown or corrupted reminders. if (reminderType != null) { String workflowName = rs.getString("title"); // Recipient timezone (if available) or sender timezone (otherwise). ZoneId zoneId = TimeZone.getTimeZone(rs.getString("timezone")).toZoneId(); LocalDateTime startDate = DateUtilities.toLocalDateTime(rs.getTimestamp("workflow_start_date"), zoneId); LocalDateTime stopDate = DateUtilities.toLocalDateTime(rs.getTimestamp("workflow_stop_date"), zoneId); generateContent(reminder, reminderType, workflowName, startDate, stopDate); } return reminder; }
Example #8
Source File: DayTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { Day d = new Day(4, 5, 2001); Calendar calendar = Calendar.getInstance( TimeZone.getTimeZone("Europe/London"), Locale.UK); assertEquals(989017199999L, d.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { d.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
Example #9
Source File: InternationalBAT.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { boolean pass = true; TimeZone tz = TimeZone.getDefault(); try { pass &= testRequiredLocales(); pass &= testRequiredEncodings(); } finally { TimeZone.setDefault(tz); } if (!pass) { System.out.println("\nSome tests failed.\n" + "If you installed the US-only J2RE for Windows, " + "failures are expected and OK.\n" + "If you installed the international J2RE, or any J2SDK, " + "or if this occurs on any platform other than Windows, " + "please file a bug report.\n" + "Unfortunately, this test cannot determine whether you " + "installed a US-only J2RE, an international J2RE, or " + "a J2SDK.\n"); throw new RuntimeException(); } }
Example #10
Source File: TimezoneDaylightSavingTimeTest.java From mariadb-connector-j with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testTimeStampUtc() throws SQLException { TimeZone.setDefault(parisTimeZone); try (Connection connection = setConnection("&serverTimezone=UTC&useServerPrepStmts=true")) { setSessionTimeZone(connection, "+00:00"); // timestamp timezone to parisTimeZone like server Timestamp currentTimeParis = new Timestamp(System.currentTimeMillis()); PreparedStatement st = connection.prepareStatement("SELECT ?"); st.setTimestamp(1, currentTimeParis); ResultSet rs = st.executeQuery(); assertTrue(rs.next()); Timestamp t1 = rs.getTimestamp(1); assertEquals(t1, currentTimeParis); } }
Example #11
Source File: DateFormatSymbols.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public String[][] getZoneStrings() { synchronized (this) { if (zoneStrings == null) { String ids[] = TimeZone.getAvailableIDs(); String newZoneStrings[][] = new String[ids.length][5]; for (int i = 0; i < ids.length; i++) { newZoneStrings[i][ZONE_ID] = ids[i]; // - time zone ID String key = ids[i].toUpperCase(); newZoneStrings[i][ZONE_LONGNAME] = getLocalizedValue(L10N_ZONE_LONGNAME + key, ids[i]); newZoneStrings[i][ZONE_SHORTNAME] = getLocalizedValue(L10N_ZONE_SHORTNAME + key, ids[i]); newZoneStrings[i][ZONE_LONGNAME_DST] = getLocalizedValue(L10N_ZONE_LONGNAME_DST + key, ids[i]); newZoneStrings[i][ZONE_SHORTNAME_DST] = getLocalizedValue(L10N_ZONE_SHORTNAME_DST + key, ids[i]); } zoneStrings = newZoneStrings; } } return zoneStrings; }
Example #12
Source File: MinuteTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithCalendar() { Minute m = new Minute(40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955766400000L, m.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { m.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
Example #13
Source File: AwsCodeCommitCredentialProvider.java From spring-cloud-config with Apache License 2.0 | 5 votes |
/** * Calculate the AWS CodeCommit password for the provided URI and AWS secret key. This * uses the algorithm published by AWS at * https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html * @param uri the codecommit repository uri * @param awsSecretKey the aws secret key * @return the password to use in the git request */ protected static String calculateCodeCommitPassword(URIish uri, String awsSecretKey) { String[] split = uri.getHost().split("\\."); if (split.length < 4) { throw new CredentialException("Cannot detect AWS region from URI", null); } String region = split[1]; Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String dateStamp = dateFormat.format(now); String shortDateStamp = dateStamp.substring(0, 8); String codeCommitPassword; try { StringBuilder stringToSign = new StringBuilder(); stringToSign.append("AWS4-HMAC-SHA256\n").append(dateStamp).append("\n") .append(shortDateStamp).append("/").append(region) .append("/codecommit/aws4_request\n") .append(bytesToHexString(canonicalRequestDigest(uri))); byte[] signedRequest = sign(awsSecretKey, shortDateStamp, region, stringToSign.toString()); codeCommitPassword = dateStamp + "Z" + bytesToHexString(signedRequest); } catch (Exception e) { throw new CredentialException("Error calculating AWS CodeCommit password", e); } return codeCommitPassword; }
Example #14
Source File: DateTimeBrowser.java From astor with GNU General Public License v2.0 | 5 votes |
String getViewTitle() { return "DateTime.getXXX() Method Calculations" + " : " + TimeZone.getDefault().getDisplayName() + " : " + " Record Count " + currFile.getLoadedFileSize(); }
Example #15
Source File: ConfigurationDO.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
public void setTimeZone(final TimeZone timeZone) { if (timeZone == null) { this.stringValue = null; } else { this.stringValue = timeZone.getID(); } }
Example #16
Source File: NotesParserTest.java From osmapi with GNU Lesser General Public License v3.0 | 5 votes |
public void testParseNoteDate() { String xml = "<note lon=\"0\" lat=\"0\">" + " <date_created>2015-12-20 22:52:30 UTC</date_created>" + "</note>"; Note note = parseOne(xml); Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.UK); c.set(2015, Calendar.DECEMBER, 20, 22, 52, 30); assertEquals(c.getTimeInMillis() / 1000, note.dateCreated.getTime() / 1000); }
Example #17
Source File: CLusterSendMsgRTCommand.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
public String getCurTime() { String fromTimeZone = "GMT+8"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); format.setTimeZone(TimeZone.getTimeZone(fromTimeZone)); String chinaDate = format.format(date); return chinaDate; }
Example #18
Source File: TimeZoneUtilsTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private static void assertSameRules(final String label, final TimeZone expected, final TimeZone actual) { if (null == expected && null == actual) return; assertNotNull(label + ": expected is null", expected); assertNotNull(label + ": actual is null", actual); final boolean same = expected.hasSameRules(actual); assertTrue(label + ": " + expected.toString() + " [[NOT SAME RULES]] " + actual.toString(), same); }
Example #19
Source File: ConfigurableTimezoneTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testTimezone() { DumperOptions options = new DumperOptions(); options.setTimeZone(TimeZone.getTimeZone("GMT+1:00")); Yaml yaml = new Yaml(options); Date date = new Date(); String output = yaml.dump(date); // System.out.println(output); assertTrue(output, output.trim().endsWith("+1:00")); Date parsed = (Date) yaml.load(output); assertEquals(date, parsed); }
Example #20
Source File: TimestampTagTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testTimestampOutMap() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Moscow")); cal.clear(); cal.set(2008, 8, 23, 14, 35, 4); Date date = cal.getTime(); Map<String, Date> map = new HashMap<String, Date>(); map.put("canonical", date); String output = dump(map); assertEquals("{canonical: !!timestamp '2008-09-23T10:35:04Z'}\n", output); }
Example #21
Source File: EsAbstractConditionQuery.java From fess with Apache License 2.0 | 5 votes |
protected String toRangeDateString(Date date, String format) { if (format.contains("epoch_millis")) { return Long.toString(date.getTime()); } else if (format.contains("date_optional_time")) { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(date); } else { return Long.toString(date.getTime()); } }
Example #22
Source File: CalendarRegression.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Maximum value for YEAR field wrong. */ public void Test4145983() { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); Date[] DATES = {new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE)}; for (int i = 0; i < DATES.length; ++i) { calendar.setTime(DATES[i]); int year = calendar.get(YEAR); int maxYear = calendar.getMaximum(YEAR); if (year > maxYear) { errln("Failed for " + DATES[i].getTime() + " ms: year=" + year + ", maxYear=" + maxYear); } } }
Example #23
Source File: NettyHttpFileHandler.java From khs-stockticker with Apache License 2.0 | 5 votes |
/** * Sets the Date header for the HTTP response * * @param response * HTTP response */ public void setDateHeader(FullHttpResponse response) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaders.Names.DATE, dateFormatter.format(time.getTime())); }
Example #24
Source File: MapperConfiguration.java From pazuzu-registry with MIT License | 5 votes |
@Bean @Primary public Jackson2ObjectMapperBuilder objectMapperBuilder() { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return builder .failOnUnknownProperties(false) .dateFormat(dateFormat) .serializationInclusion(Include.NON_NULL) .modules(new Jdk8Module(), new ProblemModule()); }
Example #25
Source File: FilterFactoryTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void issueOLINGO357() throws UnsupportedEncodingException { final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-8")); calendar.clear(); calendar.set(2011, 2, 8, 14, 21, 12); final URIFilter filter = getFilterFactory().ge("OrderDate", calendar); assertEquals("(OrderDate ge " + Encoder.encode("2011-03-08T14:21:12-08:00") + ")", filter.build()); }
Example #26
Source File: DateTimeUtilsTest.java From ews-java-api with MIT License | 5 votes |
@Test public void testDateTimeZulu() { String dateString = "2015-01-08T10:11:12Z"; Date parsed = DateTimeUtils.convertDateTimeStringToDate(dateString); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.setTime(parsed); assertEquals(2015, calendar.get(Calendar.YEAR)); assertEquals(0, calendar.get(Calendar.MONTH)); assertEquals(8, calendar.get(Calendar.DATE)); assertEquals(10, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals(11, calendar.get(Calendar.MINUTE)); assertEquals(12, calendar.get(Calendar.SECOND)); }
Example #27
Source File: ClickHouseConnection.java From ClickHouse-Native-JDBC with Apache License 2.0 | 5 votes |
private static PhysicalInfo.ServerInfo serverInfo(PhysicalConnection physical, ClickHouseConfig configure) throws SQLException { try { long reversion = ClickHouseDefines.CLIENT_REVERSION; physical.sendHello("client", reversion, configure.database(), configure.username(), configure.password()); HelloResponse response = physical.receiveHello(configure.queryTimeout(), null); TimeZone timeZone = TimeZone.getTimeZone(response.serverTimeZone()); return new PhysicalInfo.ServerInfo(configure, response.reversion(), timeZone, response.serverDisplayName()); } catch (SQLException rethrows) { physical.disPhysicalConnection(); throw rethrows; } }
Example #28
Source File: SupplementalJapaneseEraTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private long since() { return new Calendar.Builder() .setCalendarType("japanese") .setTimeZone(TimeZone.getTimeZone("GMT")) .setFields(ERA, 5) .setDate(SupplementalJapaneseEraTest.NEW_ERA_YEAR, SupplementalJapaneseEraTest.NEW_ERA_MONTH, SupplementalJapaneseEraTest.NEW_ERA_DAY) .build() .getTimeInMillis(); }
Example #29
Source File: TestZonedDateTimeSerialization.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Test public void testDeserializationWithTypeInfo01WithTimeZone() throws Exception { ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(123456789L, 183917322), Z2); ObjectMapper mapper = newMapperBuilder(TimeZone.getDefault()) .addMixIn(Temporal.class, MockObjectConfiguration.class) .build(); Temporal value = mapper.readValue( "[\"" + ZonedDateTime.class.getName() + "\",123456789.183917322]", Temporal.class ); assertTrue("The value should be an ZonedDateTime.", value instanceof ZonedDateTime); assertIsEqual(date, (ZonedDateTime) value); assertEquals("The time zone is not correct.", ZoneId.systemDefault(), ((ZonedDateTime) value).getZone()); }
Example #30
Source File: UtilDateTime.java From scipio-erp with Apache License 2.0 | 5 votes |
/** Returns a TimeZone object based upon an hour offset from GMT. * @see java.util.TimeZone */ public static TimeZone toTimeZone(int gmtOffset) { if (gmtOffset > 12 || gmtOffset < -14) { throw new IllegalArgumentException("Invalid GMT offset"); } String tzId = gmtOffset > 0 ? "Etc/GMT+" : "Etc/GMT"; return TimeZone.getTimeZone(tzId + gmtOffset); }