List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:gr.cti.android.experimentation.controller.api.HistoryController.java
@PostConstruct public void init() { final TimeZone tz = TimeZone.getTimeZone("UTC"); df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz);//from ww w . j ava 2 s . co m df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df1.setTimeZone(tz); }
From source file:com.redhat.lightblue.metadata.types.DateTypeTest.java
@Test public void testToJson() { DateFormat dateFormat = new SimpleDateFormat(DateType.DATE_FORMAT_STR); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); String date = dateFormat.format(new Date()); JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true); JsonNode jsonNode = dateType.toJson(jsonNodeFactory, date); assertTrue(jsonNode.asText().equals(date)); }
From source file:it.jugpadova.blol.FeedsBoTest.java
public void testConvertDateAndTime() throws ParseException { SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); df.setTimeZone(TimeZone.getTimeZone("GMT")); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone("GMT"); Date d = df.parse("18/09/2009"); net.fortuna.ical4j.model.Date cd1 = feedsBo.convertDateAndTime(d, "12:00 AM", tz); assertEquals("20090918T120000", cd1.toString()); net.fortuna.ical4j.model.Date cd2 = feedsBo.convertDateAndTime(d, "05:00 PM", tz); assertEquals("20090918T170000", cd2.toString()); }
From source file:api.util.JsonUtil.java
public static Date asDate(Object val) { if (val == JSONObject.NULL) return null; if (val instanceof String) { String stringValue = (String) val; try {/*from w w w. jav a2 s .c o m*/ // try ISO 8601 Calendar cal = DatatypeConverter.parseDateTime(stringValue); if (!iso8601Timezone.matcher(stringValue).matches()) { // timezone is absent from input string. Assume UTC cal.setTimeZone(TimeZone.getTimeZone("UTC")); } return cal.getTime(); } catch (IllegalArgumentException iae) { // fallback to RFC 2822 for (String format : new String[] { "EEE, dd MMM yyyy HH:mm:ss Z", "dd MMM yyyy HH:mm:ss Z", "EEE, dd MMM yyyy HH:mm Z", "dd MMM yyyy HH:mm Z", "EEE, dd MMM yyyy HH:mm:ss", "dd MMM yyyy HH:mm:ss", "EEE, dd MMM yyyy HH:mm", "dd MMM yyyy HH:mm" }) { SimpleDateFormat rfc2822Fmt = new SimpleDateFormat(format, Locale.ENGLISH); rfc2822Fmt.setTimeZone(TimeZone.getTimeZone("UTC")); try { return rfc2822Fmt.parse(stringValue); } catch (ParseException e) { } } } } else if (val instanceof Number) { return new Date(((Number) val).longValue() * 1000); } throw new IllegalArgumentException( "Value is expected to be a unix timestamp or a string in either ISO 8601 or RFC 2822 format: " + val); }
From source file:com.concursive.connect.web.modules.calendar.utils.CalendarBeanUtils.java
public static void updateValues(CalendarBean bean, PortletRequest request, User user) throws SQLException { // Set the timezone if it is different from the server timezone String tZone = user.getTimeZone(); if (tZone != null && (bean.getTimeZone() == null || !bean.getTimeZone().hasSameRules(TimeZone.getTimeZone(tZone)))) { LOG.debug("Setting timezone from user to: " + tZone); bean.setTimeZone(TimeZone.getTimeZone(tZone)); }/*from ww w .j a va 2 s.c o m*/ if (request.getParameter("primaryMonth") != null) { bean.setPrimaryMonth(Integer.parseInt(request.getParameter("primaryMonth"))); } if (request.getParameter("primaryYear") != null) { bean.setPrimaryYear(Integer.parseInt(request.getParameter("primaryYear"))); } if (request.getParameter("alertsView") != null) { bean.setCalendarDetailsView(request.getParameter("alertsView")); } if (request.getParameter("userId") != null) { bean.setSelectedUserId(Integer.parseInt(request.getParameter("userId"))); } if (request.getParameter("day") != null) { bean.setDaySelected(Integer.parseInt(request.getParameter("day"))); } if (request.getParameter("month") != null) { bean.setMonthSelected(Integer.parseInt(request.getParameter("month"))); } if (request.getParameter("year") != null) { bean.setYearSelected(Integer.parseInt(request.getParameter("year"))); } if (request.getParameter("startMonthOfWeek") != null) { bean.setStartMonthOfWeek(Integer.parseInt(request.getParameter("startMonthOfWeek"))); } if (request.getParameter("startDayOfWeek") != null) { bean.setStartDayOfWeek(Integer.parseInt(request.getParameter("startDayOfWeek"))); } }
From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionResource.java
/** * Retrieves the list of all steps by job execution id. * * @param jobExecutionId the job execution id * @return the response/*from w w w . j a v a 2 s. c o m*/ */ @GET @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions("seed:monitoring:batch:read") public Response list(@PathParam("jobExecutionId") long jobExecutionId) { Collection<StepExecutionRepresentation> stepExecutionRepresentations = new ArrayList<StepExecutionRepresentation>(); try { for (StepExecution stepExecution : jobService.getStepExecutions(jobExecutionId)) { if (stepExecution.getId() != null) { stepExecutionRepresentations .add(new StepExecutionRepresentation(stepExecution, TimeZone.getTimeZone("GMT"))); } } } catch (NoSuchJobExecutionException e) { return Response.status(Response.Status.BAD_REQUEST) .entity("There is no such job execution (" + jobExecutionId + ")").type(MediaType.TEXT_PLAIN) .build(); } return Response.ok(stepExecutionRepresentations).build(); }
From source file:cn.loveapple.client.android.util.DateUtil.java
/** * ???/*from w w w . ja v a 2 s. co m*/ * * @see SimpleDateFormat ??? * @param source ? * @param pattern * @param timeZone * @return ????????<code>null</code>????????? */ public static Date parseDate(String source, String pattern, String timeZone) { if (source == null || pattern == null) { return null; } try { SimpleDateFormat format = new SimpleDateFormat(pattern); if (StringUtils.isNotEmpty(timeZone)) { format.setTimeZone(TimeZone.getTimeZone(timeZone.trim())); } return format.parse(source); } catch (Exception e) { return null; } }
From source file:org.openmeetings.utils.math.TimezoneUtil.java
/** * Returns the timezone based on the user profile, if not return the * timezone from the server//from w w w . jav a 2s . c o m * * @param user * @return */ public TimeZone getTimezoneByUser(Users user) { if (user != null && user.getOmTimeZone() != null) { TimeZone timeZone = TimeZone.getTimeZone(user.getOmTimeZone().getIcal()); if (timeZone != null) { return timeZone; } } // if user has not time zone get one from the server configuration Configuration conf = cfgManagement.getConfKey(3L, "default.timezone"); if (conf != null) { OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(conf.getConf_value()); TimeZone timeZoneByOmTimeZone = TimeZone.getTimeZone(omTimeZone.getIcal()); if (timeZoneByOmTimeZone != null) { return timeZoneByOmTimeZone; } } // If everything fails take the servers default one log.error( "There is no correct time zone set in the configuration of OpenMeetings for the key default.timezone or key is missing in table, using default locale!"); return TimeZone.getDefault(); }
From source file:com.userhook.util.UHOperation.java
public void createSession(UserHook.UHSuccessListener listener) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ"); format.setTimeZone(TimeZone.getTimeZone("UTC")); String date = format.format(new Date()); Map<String, Object> data = new HashMap<>(); data.put("sessions", "1"); data.put("last_launch", date); updateSessionData(data, listener);//from w w w . j av a 2 s . com // prefetch message templates fetchMessageTemplates(); }
From source file:su90.etl.controller.SlaveController.java
private Result parse_imps(Iterator<String> iterator) { Result tmp = new Result(); int i = 0;//from w ww .j a v a 2s .c o m // unix_timestamp,transaction_id,connection_type,device_type,count while (iterator.hasNext()) { String tmpstr = iterator.next(); switch (i) { case 0: // tmp.setIso8601_timestamp(new Timestamp(Long.parseLong(tmpstr)).toLocaleString()); tmp.setIso8601_timestamp(DateFormatUtils.format(Long.parseLong(tmpstr) * 1000, "yyyy-MM-dd'T'HH:mm:ssZZ", TimeZone.getTimeZone("America/Los_Angeles"))); break; case 1: tmp.setTransaction_id(tmpstr); break; case 2: tmp.setConnection_type(TypeParser.get(Integer.parseInt(tmpstr))); break; case 3: tmp.setDevice_type(DeviceTypeParser.get(Integer.parseInt(tmpstr))); break; case 4: tmp.setImps(Integer.parseInt(tmpstr)); break; } i++; } return tmp; }