List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:agileinterop.AgileInterop.java
private static JSONObject getPSRCellValues(String body) throws UnsupportedOperationException, YamlException, APIException { String[] psrNumbers = body.split(","); // Trim and upper case all PSR numbers for (int i = 0; i < psrNumbers.length; i++) { psrNumbers[i] = psrNumbers[i].trim().toUpperCase(); }//from www. ja v a2 s . c o m Map<String, Map<String, String>> data = new HashMap<>(); for (String psrNumber : psrNumbers) { Map<String, String> psrData = new HashMap<>(); IServiceRequest psr = (IServiceRequest) Agile.session.getObject(IServiceRequest.OBJECT_TYPE, psrNumber); ICell[] cells = psr.getCells(); for (ICell cell : cells) { String cellName = cell.getName(); if (cell.getDataType() == DataTypeConstants.TYPE_DATE) { if (cell.getValue() != null) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a zz"); sdf.setTimeZone(TimeZone.getTimeZone("Europe/London")); psrData.put(cell.getName(), sdf.format((Date) cell.getValue())); } else { psrData.put(cell.getName(), cell.toString()); } } else { psrData.put(cell.getName(), cell.toString()); } } data.put(psrNumber, psrData); } JSONObject obj = new JSONObject(); obj.put("data", data); return obj; }
From source file:net.hasor.search.utils.DateUtil.java
/** * Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDate * <p/>/*from www . java 2 s .c om*/ * Parses the date value using the given date formats. * * @param dateValue the date value to parse * @param dateFormats the date formats to use * @param startDate During parsing, two digit years will be placed in the range * <code>startDate</code> to <code>startDate + 100 years</code>. This value may * be <code>null</code>. When <code>null</code> is given as a parameter, year * <code>2000</code> will be used. * @return the parsed date * @throws ParseException if none of the dataFormats could parse the dateValue */ public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) throws ParseException { if (dateValue == null) { throw new IllegalArgumentException("dateValue is null"); } if (dateFormats == null) { dateFormats = DEFAULT_HTTP_CLIENT_PATTERNS; } if (startDate == null) { startDate = DEFAULT_TWO_DIGIT_YEAR_START; } // trim single quotes around date if present // see issue #5279 if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) { dateValue = dateValue.substring(1, dateValue.length() - 1); } SimpleDateFormat dateParser = null; Iterator formatIter = dateFormats.iterator(); while (formatIter.hasNext()) { String format = (String) formatIter.next(); if (dateParser == null) { dateParser = new SimpleDateFormat(format, Locale.ROOT); dateParser.setTimeZone(GMT); dateParser.set2DigitYearStart(startDate); } else { dateParser.applyPattern(format); } try { return dateParser.parse(dateValue); } catch (ParseException pe) { // ignore this exception, we will try the next format } } // we were unable to parse the date throw new ParseException("Unable to parse the date " + dateValue, 0); }
From source file:com.clustercontrol.calendar.util.CalendarUtil.java
/** * - ????????/*w w w . j a v a 2 s . c om*/ * * @param detailInfo * @param date * @return ??? True */ public static boolean isRunByDetailTime(CalendarDetailInfo detailInfo, Date date) { //? (00:00:00 - 24:00:00) long timezoneOffset = HinemosTime.getTimeZoneOffset(); //null? if (detailInfo.getTimeFrom() == null || detailInfo.getTimeTo() == null) { m_log.warn("detailInfo.getTime is NULL"); return false; } //?????00:00:00? SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); sdf.setTimeZone(HinemosTime.getTimeZone()); String strNow = sdf.format(date); Date dateNow = null; try { dateNow = sdf.parse(strNow); /* * ???????1970/1/1 ??????? * ????????????????? */ long from = detailInfo.getTimeFrom() + timezoneOffset + dateNow.getTime(); long to = detailInfo.getTimeTo() + timezoneOffset + dateNow.getTime(); m_log.trace("this Time " + date); m_log.trace("DetailTimeFrom " + new Date(from)); m_log.trace("DetailTimeTo " + new Date(to)); //???Long Long checkTime = date.getTime(); //?????? if (from <= checkTime && checkTime < to) { return true; } } catch (ParseException e) { e.printStackTrace(); } // ?????????? return false; }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static DateFormat getDateFormatterforOnlyDate(HttpServletRequest request) throws SessionExpiredException { String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); dateformat = "MMMM d, yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf;//from w w w.j av a2 s . c om }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static DateFormat getDateFormatter(HttpServletRequest request) throws SessionExpiredException { String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); if (timeformat.equals("1")) { dateformat = "MMMM d, yyyy hh:mm:ss aa"; } else//from w ww.ja v a 2 s . co m dateformat = "MMMM d, yyyy HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf; }
From source file:com.nubits.nubot.utils.Utils.java
public static String calcDate(long millisecs) { String timezone = "UTC"; SimpleDateFormat date_format = new SimpleDateFormat("MMM dd yyyy HH:mm:ss.SSS"); date_format.setTimeZone(TimeZone.getTimeZone("timezone")); Date resultdate = new Date(millisecs); return date_format.format(resultdate) + " " + timezone; }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static DateFormat getPrefDateFormatter(HttpServletRequest request, String pref) throws SessionExpiredException { String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); if (timeformat.equals("1")) { dateformat = pref.replace('H', 'h'); if (!dateformat.equals(pref)) dateformat += " a"; } else// w w w . j av a2 s . co m dateformat = pref; SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf; }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static DateFormat getUserDateFormatter(HttpServletRequest request, Session session) throws SessionExpiredException { KWLDateFormat df = (KWLDateFormat) session.load(KWLDateFormat.class, getDateFormatID(request)); String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); if (timeformat.equals("1")) { dateformat = df.getJavaForm().replace('H', 'h'); if (!dateformat.equals(df.getJavaForm())) dateformat += " a"; } else/* w w w . java 2 s . c o m*/ dateformat = df.getJavaForm(); SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf; }
From source file:com.krawler.esp.handlers.AuthHandler.java
public static DateFormat getUserDateFormatter(HttpServletRequest request, HibernateTemplate hibernateTemplate) throws SessionExpiredException { KWLDateFormat df = (KWLDateFormat) hibernateTemplate.load(KWLDateFormat.class, getDateFormatID(request)); String dateformat = ""; String timeformat = AuthHandler.getUserTimeFormat(request); if (timeformat.equals("1")) { dateformat = df.getJavaForm().replace('H', 'h'); if (!dateformat.equals(df.getJavaForm())) dateformat += " a"; } else// ww w .ja v a2s. com dateformat = df.getJavaForm(); SimpleDateFormat sdf = new SimpleDateFormat(dateformat); sdf.setTimeZone(TimeZone.getTimeZone("GMT" + getTimeZoneDifference(request))); return sdf; }
From source file:com.microsoft.windowsazure.messaging.Registration.java
/** * Parses an UTC date string into a Date object * @param dateString The date string to parse * @return The Date object// www. j a v a 2s .c o m * @throws java.text.ParseException */ private static Date UTCDateStringToDate(String dateString) throws ParseException { // Change Z to +00:00 to adapt the string to a format // that can be parsed in Java String s = dateString.replace("Z", "+00:00"); try { // Remove the ":" character to adapt the string to a // format that can be parsed in Java s = s.substring(0, 26) + s.substring(27); } catch (IndexOutOfBoundsException e) { throw new ParseException("The 'updated' value has an invalid format", 26); } // Parse the well-formatted date string SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ", Locale.getDefault()); dateFormat.setTimeZone(TimeZone.getDefault()); Date date = dateFormat.parse(s); return date; }