List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:org.kuali.rice.ken.util.Util.java
/** date formats are not thread safe so creating a new one each time it is needed. */ private static DateFormat createZulu() { final DateFormat df = new SimpleDateFormat(ZULU_FORMAT); df.setTimeZone(ZULU_TZ); return df;/* w ww . j ava 2s . c o m*/ }
From source file:Main.java
public static Date getDateFromString(String dateString) { DateFormat inputFormat = null; if (dateString == null) { return null; }//w w w. j a v a 2s .co m if (dateString.length() == 19) inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); if (dateString.length() == 10) inputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); if (inputFormat == null) { return null; } inputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date parsed = null; try { parsed = inputFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return parsed; }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTUtilities.java
public static Date parseCoTDate(String dateString) throws Exception { if (!dateString.isEmpty()) { DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); formatter1.setTimeZone(TimeZone.getTimeZone("Zulu")); DateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); formatter2.setTimeZone(TimeZone.getTimeZone("Zulu")); Date date = null;/*from www.j av a 2 s . com*/ try { if (date == null) date = (Date) formatter1.parse(dateString); } catch (ParseException ex) { } try { if (date == null) date = (Date) formatter2.parse(dateString); } catch (ParseException ex) { } return date; } return null; }
From source file:com.krawler.spring.authHandler.authHandler.java
public static DateFormat getDateFormat(JSONObject jobj) throws JSONException { String tZStr = jobj.has(Constants.tzdiff) ? jobj.getString(Constants.tzdiff) : null; DateFormat df = getDateMDYFormatter(); if (tZStr != null) { TimeZone zone = TimeZone.getTimeZone(Constants.GMT + tZStr); df.setTimeZone(zone); }/* w ww .j a va 2 s . c o m*/ return df; }
From source file:com.krawler.spring.authHandler.authHandler.java
public static DateFormat getDateFormatterWithTimeZone(HttpServletRequest request) throws SessionExpiredException { String tZStr = sessionHandlerImpl.getTimeZoneDifference(request); DateFormat df = authHandler.getDateMDYFormatter(request); if (tZStr != null) { TimeZone zone = TimeZone.getTimeZone("GMT" + tZStr); df.setTimeZone(zone); }//from w ww. j a v a2 s . c om return df; }
From source file:com.krawler.spring.authHandler.authHandler.java
public static DateFormat getDateFormatterWithTimeZoneForExport(HttpServletRequest request) throws SessionExpiredException { String tZStr = sessionHandlerImpl.getTimeZoneDifference(request); DateFormat df = authHandler.getNewDateFormatter(request); if (tZStr != null) { TimeZone zone = TimeZone.getTimeZone("GMT" + tZStr); df.setTimeZone(zone); }/*from w w w .j a v a 2 s .c o m*/ return df; }
From source file:com.ryderbot.utils.ModelUtils.java
public static Job generateJob(NamedNodeMap attributes) { DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); Long jobID = Long.parseLong(attributes.getNamedItem("jobID").getNodeValue()); Long installerID = Long.parseLong(attributes.getNamedItem("installerID").getNodeValue()); String installerName = attributes.getNamedItem("installerName").getNodeValue(); Long facilityID = Long.parseLong(attributes.getNamedItem("facilityID").getNodeValue()); Long solarSystemID = Long.parseLong(attributes.getNamedItem("solarSystemID").getNodeValue()); String solarSystemName = attributes.getNamedItem("solarSystemName").getNodeValue(); Long stationID = Long.parseLong(attributes.getNamedItem("stationID").getNodeValue()); Integer activityID = Integer.parseInt(attributes.getNamedItem("activityID").getNodeValue()); Long blueprintID = Long.parseLong(attributes.getNamedItem("blueprintID").getNodeValue()); ;//from w w w.j a v a 2 s .co m Long blueprintTypeID = Long.parseLong(attributes.getNamedItem("blueprintTypeID").getNodeValue()); String blueprintTypeName = attributes.getNamedItem("blueprintTypeName").getNodeValue(); Long blueprintLocationID = Long.parseLong(attributes.getNamedItem("blueprintLocationID").getNodeValue()); Long outputLocationID = Long.parseLong(attributes.getNamedItem("outputLocationID").getNodeValue()); Integer runs = Integer.parseInt(attributes.getNamedItem("runs").getNodeValue()); Double cost = Double.parseDouble(attributes.getNamedItem("cost").getNodeValue()); Long teamID = Long.parseLong(attributes.getNamedItem("teamID").getNodeValue()); Integer licensedRuns = Integer.parseInt(attributes.getNamedItem("licensedRuns").getNodeValue()); Double probability = Double.parseDouble(attributes.getNamedItem("probability").getNodeValue()); Long productTypeID = Long.parseLong(attributes.getNamedItem("productTypeID").getNodeValue()); String productTypeName = attributes.getNamedItem("productTypeName").getNodeValue(); Integer status = Integer.parseInt(attributes.getNamedItem("status").getNodeValue()); Long timeInSeconds = Long.parseLong(attributes.getNamedItem("timeInSeconds").getNodeValue()); Long completedCharacterID = Long.parseLong(attributes.getNamedItem("completedCharacterID").getNodeValue()); Integer successfulRuns = Integer.parseInt(attributes.getNamedItem("successfulRuns").getNodeValue()); Date startDate = null; Date endDate = null; Date pauseDate = null; Date completedDate = null; try { startDate = dateFormatter.parse(attributes.getNamedItem("startDate").getNodeValue()); endDate = dateFormatter.parse(attributes.getNamedItem("endDate").getNodeValue()); pauseDate = dateFormatter.parse(attributes.getNamedItem("pauseDate").getNodeValue()); completedDate = dateFormatter.parse(attributes.getNamedItem("completedDate").getNodeValue()); } catch (DOMException | ParseException e) { } Job job = new Job(jobID); job.setInstallerID(installerID); job.setInstallerName(installerName); job.setFacilityID(facilityID); job.setSolarSystemID(solarSystemID); job.setSolarSystemName(solarSystemName); job.setStationID(stationID); job.setBlueprintTypeName(blueprintTypeName); job.setActivityID(activityID); job.setBlueprintID(blueprintID); job.setBlueprintTypeID(blueprintTypeID); job.setBlueprintLocationID(blueprintLocationID); job.setOutputLocationID(outputLocationID); job.setRuns(runs); job.setCost(cost); job.setTeamID(teamID); job.setLicensedRuns(licensedRuns); job.setProbability(probability); job.setProductTypeID(productTypeID); job.setProductTypeName(productTypeName); job.setStatus(status); job.setTimeInSeconds(timeInSeconds); job.setCompletedCharacterID(completedCharacterID); job.setSuccessfulRuns(successfulRuns); job.setStartDate(startDate); job.setEndDate(endDate); job.setPauseDate(pauseDate); job.setCompletedDate(completedDate); return job; }
From source file:com.cubusmail.server.services.ConvertUtil.java
/** * Convert dedicated messages to string arrays for GridList. * // ww w. ja v a 2s . c o m * @param context * @param preferences * @param currentFolder * @param pageSize * @param msgs * @return * @throws MessagingException */ public static GWTMessageRecord[] convertMessagesToStringArray(ApplicationContext context, Preferences preferences, IMAPFolder currentFolder, int pageSize, Message msgs[]) throws MessagingException { GWTMessageRecord[] result = new GWTMessageRecord[pageSize]; // get date formats for message list date Locale locale = SessionManager.get().getLocale(); TimeZone timezone = SessionManager.get().getTimeZone(); String datePattern = context.getMessage(CubusConstants.MESSAGELIST_DATE_FORMAT_PATTERN, null, locale); String timePattern = context.getMessage(CubusConstants.MESSAGELIST_TIME_FORMAT_PATTERN, null, locale); NumberFormat sizeFormat = MessageUtils.createSizeFormat(locale); DateFormat dateFormat = null; DateFormat timeFormat = null; if (preferences.isShortTimeFormat()) { dateFormat = new SimpleDateFormat(datePattern, locale); timeFormat = new SimpleDateFormat(timePattern, locale); timeFormat.setTimeZone(timezone); } else { dateFormat = new SimpleDateFormat(datePattern + " " + timePattern, locale); } dateFormat.setTimeZone(timezone); Date today = Calendar.getInstance(timezone).getTime(); for (int i = 0; i < pageSize; i++) { result[i] = new GWTMessageRecord(); if (preferences.isShortTimeFormat() && DateUtils.isSameDay(today, msgs[i].getSentDate())) { // show only time convertToStringArray(currentFolder, msgs[i], result[i], timeFormat, sizeFormat); } else { convertToStringArray(currentFolder, msgs[i], result[i], dateFormat, sizeFormat); } } return result; }
From source file:org.exoplatform.social.service.rest.RestUtils.java
private static String formatDateToISO8601(Date date) { TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'"); df.setTimeZone(tz); return df.format(date); }
From source file:com.clustercontrol.jobmanagement.util.ParameterUtil.java
/** * * ?????// w w w .j a va2s. c om * * @param paramId ID * @param sessionId ID * @param jobSessionEntity * @return * @throws JobInfoNotFound */ private static String getJobSessionValue(String paramId, String sessionId, JobSessionEntity jobSessionEntity) throws JobInfoNotFound { m_log.debug("getJobSessionValue() start paramId=" + paramId + ",sessionId=" + sessionId); String ret = null; if (paramId.equals(SystemParameterConstant.SESSION_ID)) { // ID ret = sessionId; } else { if (jobSessionEntity == null) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); // ?? jobSessionEntity = em.find(JobSessionEntity.class, sessionId, ObjectPrivilegeMode.READ); if (jobSessionEntity == null) { JobInfoNotFound je = new JobInfoNotFound( "JobSessionEntity.findByPrimaryKey" + ", sessionId = " + sessionId); m_log.info( "getJobParameterValue() : " + je.getClass().getSimpleName() + ", " + je.getMessage()); je.setSessionId(sessionId); throw je; } } if (paramId.equals(SystemParameterConstant.START_DATE)) { // DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(HinemosTime.getTimeZone()); ret = df.format(jobSessionEntity.getScheduleDate()); } else if (paramId.equals(SystemParameterConstant.TRIGGER_TYPE)) { // ? Locale locale = NotifyUtil.getNotifyLocale(); ret = Messages.getString( JobTriggerTypeConstant.typeToMessageCode(jobSessionEntity.getTriggerType()), locale); } else if (paramId.equals(SystemParameterConstant.TRIGGER_INFO)) { // ? ret = jobSessionEntity.getTriggerInfo(); } } m_log.debug("getJobSessionValue() end paramId=" + paramId + ",sessionId=" + sessionId + ",value=" + ret); return ret; }