List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:net.sourceforge.js3tream.util.Access.java
/******************************************************* * @throws Exception//from www. j a va 2 s. c om ******************************************************/ public Access() throws Exception { this.calFormat_ = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); this.calFormat_.setTimeZone(TimeZone.getTimeZone("GMT")); this.mac_ = Mac.getInstance(HMAC_SHA1); this.mac_.init(new SecretKeySpec(Access.accessSecret_.getBytes(), HMAC_SHA1)); }
From source file:jp.classmethod.aws.brian.utils.GsonFactoryBean.java
@Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("Universal")); return new JsonPrimitive(sdf.format(src)); }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
private static Date parseDate(String value) throws ParseException { DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale); format.setTimeZone(TimeZone.getTimeZone("GMT")); return (Date) parse(format, value); }//from www . j a v a 2s . co m
From source file:com.imaginary.home.controller.HomeController.java
static public @Nonnull String formatDate(@Nonnull Date when) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(when);// www.j a v a2 s . c om return fmt.format(cal.getTime()); }
From source file:com.sonymobile.tools.gerrit.gerritevents.dto.events.EventCreatedOnTest.java
/** * Given an event in JSON format/*w w w . java 2 s . c o m*/ * When it is converted to an Event Object * Then the eventCreatedOn attribute can be parsed as a Date. * @throws IOException if we cannot load json from file. */ @Test public void fromJsonShouldProvideValidDateFromEventCreatedOn() throws IOException { InputStream stream = getClass().getResourceAsStream("DeserializeEventCreatedOnTest.json"); String json = IOUtils.toString(stream); JSONObject jsonObject = JSONObject.fromObject(json); GerritEvent evt = GerritJsonEventFactory.getEvent(jsonObject); GerritTriggeredEvent gEvt = (GerritTriggeredEvent) evt; Date dt = gEvt.getEventCreatedOn(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("UTC")); System.out.println(df.format(dt)); String expectDateString = "2014-12-09 14:02:52"; assertEquals(expectDateString, df.format(dt)); }
From source file:name.persistent.behaviours.PURLValidationSupport.java
private XMLGregorianCalendar today() throws DatatypeConfigurationException { GregorianCalendar cal;/*from w w w .j a v a 2s .c om*/ XMLGregorianCalendar today; int n = DatatypeConstants.FIELD_UNDEFINED; DatatypeFactory f = DatatypeFactory.newInstance(); cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); today = f.newXMLGregorianCalendar(cal); today.setTime(n, n, n, n); return today; }
From source file:net.logstash.logback.composite.FormattedTimestampJsonProvider.java
public void setTimeZone(String timeZoneId) { this.timeZone = TimeZone.getTimeZone(timeZoneId); }
From source file:at.florian_lentsch.expirysync.NotifyChecker.java
private static long getFirstStartMillis(Context appContext) { final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE); long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1); if (firstStartMillis == -1) { return -1; }// ww w .ja v a2 s . c o m Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC")); midnight.set(Calendar.HOUR_OF_DAY, 0); midnight.set(Calendar.MINUTE, 0); midnight.set(Calendar.SECOND, 0); midnight.set(Calendar.MILLISECOND, 0); // add "today at 0:00" to the ms value for the alarm (else the alarm // would be scheduled for 1970-01-01): firstStartMillis += midnight.getTimeInMillis(); // if we're already past the alarm time today, we need to add another // day: if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) { firstStartMillis += AlarmManager.INTERVAL_DAY; } return firstStartMillis; }
From source file:com.xeiam.xchange.btce.service.marketdata.BTCETickerJSONTest.java
@Test public void testUnmarshal() throws IOException { // Read in the JSON from the example resources InputStream is = BTCETickerJSONTest.class.getResourceAsStream("/marketdata/example-ticker-data.json"); // Use Jackson to parse it ObjectMapper mapper = new ObjectMapper(); BTCETicker BTCETicker = mapper.readValue(is, BTCETicker.class); // Verify that the example data was unmarshalled correctly assertThat(BTCETicker.getTicker().getLast()).isEqualTo(new BigDecimal("13.07")); assertThat(BTCETicker.getTicker().getHigh()).isEqualTo(new BigDecimal("13.23")); assertThat(BTCETicker.getTicker().getLow()).isEqualTo(new BigDecimal("13")); assertThat(BTCETicker.getTicker().getVol()).isEqualTo(new BigDecimal("40418.44988")); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); f.setTimeZone(TimeZone.getTimeZone("UTC")); String dateString = f.format(DateUtils.fromMillisUtc(BTCETicker.getTicker().getServerTime() * 1000L)); assertThat(dateString).isEqualTo("2012-12-22 19:12:09"); }
From source file:com.blackducksoftware.integration.jira.task.issue.HubIssueTrackerHandler.java
public HubIssueTrackerHandler(final JiraServices jiraServices, final JiraSettingsService jiraSettingsService, final BomComponentIssueRequestService issueRequestService) { this.jiraServices = jiraServices; this.jiraSettingsService = jiraSettingsService; this.issueRequestService = issueRequestService; dateFormatter = new SimpleDateFormat(RestConnection.JSON_DATE_FORMAT); dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); }