List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:com.sun.socialsite.util.UtilitiesModel.java
/** * Format date using SimpleDateFormat format string. *///from w w w .j av a2 s.c om public static String formatDate(Date d, String fmt, TimeZone tzOverride) { if (d == null || fmt == null) return fmt; SimpleDateFormat format = new SimpleDateFormat(fmt); format.setTimeZone(tzOverride); return format.format(d); }
From source file:com.xerox.amazonws.common.AWSQueryConnection.java
/** * Generate an rfc822 date for use in the Date HTTP header. *//*from w w w.ja v a 2 s. c o m*/ private static String httpDate() { final String DateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"; SimpleDateFormat format = new SimpleDateFormat(DateFormat, Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format.format(new Date()); }
From source file:com.ykun.commons.utils.commons.DateUtils.java
/** * @param date Date// w w w .j av a2 s .c o m * @param pattern ? * @param timezone * @return * @throws * @Description:Date??? */ public static String dateToString(Date date, String pattern, TimeZone timezone) { SimpleDateFormat dateFormat = null; if (null == pattern || "".equals(pattern)) { dateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS); } else { dateFormat = new SimpleDateFormat(pattern); } dateFormat.setTimeZone(timezone); return dateFormat.format(date); }
From source file:com.clustercontrol.util.apllog.AplLogger.java
private static void putSyslog(OutputBasicInfo notifyInfo) { /** syslog//from ww w .j ava 2s . c o m * ID,,ID,ID,,? */ MessageFormat syslogfmt = new MessageFormat("hinemos: {0},{1},{2},{3},{4}"); // Locale locale = NotifyUtil.getNotifyLocale(); String priorityStr = Messages.getString(PriorityConstant.typeToMessageCode(notifyInfo.getPriority()), locale); Object[] args = { notifyInfo.getPluginId(), notifyInfo.getApplication(), notifyInfo.getMonitorId(), priorityStr, HinemosMessage.replace(notifyInfo.getMessage(), locale), notifyInfo.getMessageOrg() }; String logmsg = syslogfmt.format(args); // ? SimpleDateFormat sdf = new SimpleDateFormat(SendSyslog.HEADER_DATE_FORMAT, Locale.US); sdf.setTimeZone(HinemosTime.getTimeZone()); String timeStamp = sdf.format(HinemosTime.getDateInstance()); ///// // ?(internal.syslog) //// String hosts = HinemosPropertyUtil.getHinemosPropertyStr("internal.syslog.host", "192.168.1.1,192.168.1.2"); String[] syslogHostList = hosts.split(","); int syslogPort = HinemosPropertyUtil.getHinemosPropertyNum("internal.syslog.port", Long.valueOf(514)) .intValue(); String syslogFacility = HinemosPropertyUtil.getHinemosPropertyStr("internal.syslog.facility", "daemon"); String syslogSeverity = HinemosPropertyUtil.getHinemosPropertyStr("internal.syslog.severity", "alert"); for (String syslogHost : syslogHostList) { log.debug("putSyslog() syslogHost = " + syslogHost + ", syslogPort = " + syslogPort + ", syslogFacility = " + syslogFacility + ", syslogSeverity = " + syslogSeverity + ", logmsg = " + logmsg + ", timeStamp = " + timeStamp); try { new NotifyControllerBean().sendAfterConvertHostname(syslogHost, syslogPort, syslogFacility, syslogSeverity, INTERNAL_SCOPE, logmsg, timeStamp); } catch (InvalidRole e) { log.warn("fail putSyslog monitorId=" + notifyInfo.getMonitorId() + ", message=" + notifyInfo.getMessage()); } catch (HinemosUnknown e) { log.warn("fail putSyslog monitorId=" + notifyInfo.getMonitorId() + ", message=" + notifyInfo.getMessage()); } } }
From source file:com.google.android.gcm.demo.server.Datastore.java
/** * Gets the number of total devices.// w w w. j a v a2 s . c o m */ public static JSONArray getAllAlertsFromDataStore(int offset, int limit) { JSONArray alerts = null; Transaction txn = datastore.beginTransaction(); try { alerts = new JSONArray(); Query query = new Query(ALERTS).addSort(ALERT_TIME, SortDirection.DESCENDING); Iterable<Entity> entities = datastore.prepare(query) .asIterable(FetchOptions.Builder.withOffset(offset).limit(limit)); for (Entity entity : entities) { JSONObject alert = new JSONObject(); alert.put(ALERT_FROM, (String) entity.getProperty(ALERT_FROM)); alert.put(ALERT_MESSAGE, (String) entity.getProperty(ALERT_MESSAGE)); Date date = (Date) entity.getProperty(ALERT_TIME); SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy"); sd.setTimeZone(TimeZone.getTimeZone("IST")); alert.put(ALERT_TIME, sd.format(date)); alerts.add(alert); } txn.commit(); } finally { if (txn.isActive()) { txn.rollback(); } } return alerts; }
From source file:com.telefonica.iot.cygnus.utils.CommonUtils.java
/** * Gets the human redable version of timestamp expressed in miliseconds. * @param ts/*www . jav a2 s . c om*/ * @param addUTC * @return */ public static String getHumanReadable(long ts, boolean addUTC) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String humanRedable = sdf.format(new Date(ts)); humanRedable += "T"; sdf = new SimpleDateFormat("HH:mm:ss.S"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); humanRedable += sdf.format(new Date(ts)) + (addUTC ? "Z" : ""); return humanRedable; }
From source file:com.hp.avmon.home.service.LicenseService.java
public static Timestamp getCurrentTime() { try {//from w w w. ja va2 s . c o m Calendar cal = Calendar.getInstance(TimeZone.getDefault()); String DATE_FORMAT_HMS_d = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat formatwithHMSd = new SimpleDateFormat(DATE_FORMAT_HMS_d); formatwithHMSd.setTimeZone(TimeZone.getDefault()); Date currentdate_d = formatwithHMSd.parse(formatwithHMSd.format(cal.getTime())); long time = currentdate_d.getTime(); Timestamp currentTime = new Timestamp(time); return currentTime; } catch (Exception e) { // e.printStackTrace(); return null; } }
From source file:jp.co.nemuzuka.utils.DateTimeUtils.java
/** * SimpleDateForm?./*from w ww . ja va2s .com*/ * ThreadLocal????SimpleDateFormat???? * ???JST??? * @param pattern * @return SimpleDateFormat */ public static SimpleDateFormat createSdf(String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setTimeZone(getTimeZone()); return sdf; }
From source file:com.ykun.commons.utils.commons.DateUtils.java
/** * @param date/*from w w w. j a v a2s . co m*/ * @param pattern * @param timezone * @return * @throws * @Description:pattern???Date */ public static Date stringToDate(String date, String pattern, TimeZone timezone) { Date newDate = null; try { SimpleDateFormat dateFormat = null; if (null == pattern || "".equals(pattern)) { dateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS); } else { dateFormat = new SimpleDateFormat(pattern); } dateFormat.setTimeZone(timezone); newDate = dateFormat.parse(date); } catch (Exception e) { logger.error("Convert Date Error:", e); } return newDate; }
From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java
public static String getfilmriseParameters(Context ctx) { StringBuilder strBlr = null;/*from w w w .j av a 2s. c o m*/ try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); long longs = System.currentTimeMillis(); String timestamp = dateFormat.format(longs); ; String stringToSign = timestamp; // Query uses this string // Compute the signature and base64 encode it. String algorithm = "HmacSHA1"; SecretKeySpec key = new SecretKeySpec(SECRET_KEY.getBytes(), algorithm); Mac mac = Mac.getInstance(algorithm); mac.init(key); String signature = new String(Base64.encodeBase64(mac.doFinal(stringToSign.getBytes()))); System.out.println(signature);// required for Query signature = URLEncoder.encode(signature, "UTF-8"); strBlr = new StringBuilder(); strBlr.append(Constants.ACCESS_KEY); strBlr.append("="); strBlr.append(ACCESS_KEY); strBlr.append("&"); strBlr.append(Constants.TIME_STAMP); strBlr.append("="); strBlr.append(timestamp); strBlr.append("&"); strBlr.append(Constants.SIGNATURE); strBlr.append("="); strBlr.append(signature); strBlr.append("&"); strBlr.append(Constants.SITE); strBlr.append("="); strBlr.append(Constants.filmrise); strBlr.append("&"); strBlr.append(Constants.DEVICE); strBlr.append("="); strBlr.append("android"); return strBlr.toString(); } catch (Exception e) { } return null; }