List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:cn.loveapple.client.android.util.DateUtil.java
/** * ???/* www.ja v a2 s . c om*/ * * @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:com.esofthead.mycollab.core.utils.DateTimeUtils.java
public static String formatDate(Date date, String dateFormat, TimeZone timezone) { if (date == null) { return ""; }/*from w ww . j a va2 s . c om*/ SimpleDateFormat simpleDateFormat = getDateFormat(dateFormat); if (timezone != null) { simpleDateFormat.setTimeZone(timezone); } return simpleDateFormat.format(date); }
From source file:com.siphyc.utils.Utilities.java
public static String GetUTCdatetimeAsString() { String DATEFORMAT = "yyyy-MM-dd HH:mm:ss"; final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); final String utcTime = sdf.format(new Date()); return utcTime; }
From source file:eu.bittrade.libs.steemj.communication.CommunicationHandler.java
/** * Get a preconfigured Jackson Object Mapper instance. * //from w w w .j av a2 s . c o m * @return The object mapper. */ public static ObjectMapper getObjectMapper() { if (mapper == null) { mapper = new ObjectMapper(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat( SteemJConfig.getInstance().getDateTimePattern()); simpleDateFormat.setTimeZone(TimeZone.getTimeZone(SteemJConfig.getInstance().getTimeZoneId())); mapper.setDateFormat(simpleDateFormat); mapper.setTimeZone(TimeZone.getTimeZone(SteemJConfig.getInstance().getTimeZoneId())); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); SimpleModule simpleModule = new SimpleModule("BooleanAsString", new Version(1, 0, 0, null, null, null)); simpleModule.addSerializer(Boolean.class, new BooleanSerializer()); simpleModule.addSerializer(boolean.class, new BooleanSerializer()); mapper.registerModule(simpleModule); } return mapper; }
From source file:Main.java
public static String getFormatDate(final Date date, String type) { if (null == date || TextUtils.isEmpty(type)) { return null; }/*w w w.j a v a2 s .c o m*/ SimpleDateFormat sdf; try { sdf = new SimpleDateFormat(type, Locale.SIMPLIFIED_CHINESE); } catch (Exception e) { sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE); } TimeZone timeZone = TimeZone.getTimeZone("GMT+8"); sdf.setTimeZone(timeZone); return sdf.format(date); }
From source file:com.bourke.kitchentimer.utils.Utils.java
/** * //from w ww . j a va 2s . c om * @param totalSeconds * @param timer * @return */ public static String formatTime(long totalSeconds, int timer) { if (timer == 0) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+0")); return sdf.format(new Date(totalSeconds * 1000)); } else { String seconds = Integer.toString((int) (totalSeconds % 60)); String minutes = Integer.toString((int) (totalSeconds / 60)); if (seconds.length() < 2) { seconds = "0" + seconds; } if (minutes.length() < 2) { minutes = "0" + minutes; } return minutes + ":" + seconds; } }
From source file:HttpParser.java
public static String getDateHeader() { SimpleDateFormat format; String ret;//w ww. j a v a2 s . c o m format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); ret = "Date: " + format.format(new Date()) + " GMT"; return ret; }
From source file:moefou4j.internal.util.Moefou4JInternalParseUtil.java
public static Date getDate(final String name, final String format) throws MoefouException { SimpleDateFormat sdf = formatMap.get().get(format); if (null == sdf) { sdf = new SimpleDateFormat(format, Locale.ENGLISH); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); formatMap.get().put(format, sdf); }//from w w w . j a v a 2 s .co m try { return sdf.parse(name); } catch (final ParseException pe) { throw new MoefouException("Unexpected date format(" + name + ") returned from twitter.com", pe); } }
From source file:com.projity.util.DateTime.java
public static SimpleDateFormat utcDateFormatInstance() { SimpleDateFormat f = new SimpleDateFormat(); f.setTimeZone(DateUtils.UTC_TIME_ZONE); return f;// ww w . ja v a 2 s . c om }
From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java
/** * Gets the known username history of a UUID. All dates are in UTC. * This returns a map of player names and when they were last seen (the * approximate date they stopped using that name). * * @param uuid the uuid to lookup, cannot be null * * @return a map of names and dates (UTC), or an empty map for invalid input or unknown/non-existent history *//* ww w .ja v a2 s . c o m*/ public static Map<String, Date> getHistory(UUID uuid) { if (uuid == null) return new HashMap<>(); try { URL url = new URL("http://uuid.turt2live.com/history/" + uuid.toString().replaceAll("-", "")); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); String parsed = ""; String line; while ((line = reader.readLine()) != null) parsed += line; reader.close(); Map<String, Date> map = new HashMap<>(); Object o = JSONValue.parse(parsed); if (o instanceof JSONObject) { JSONObject jsonObject = (JSONObject) o; Object namesObj = jsonObject.get("names"); if (namesObj instanceof JSONArray) { JSONArray names = (JSONArray) namesObj; for (Object name : names) { o = name; if (o instanceof JSONObject) { JSONObject json = (JSONObject) o; Object nameObj = json.get("name"); Object dateObj = json.get("last-seen"); if (nameObj instanceof String && dateObj instanceof String) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); try { Date date = format.parse((String) dateObj); map.put((String) nameObj, date); } catch (ParseException e) { System.out.println("Could not parse " + dateObj + ": " + e.getMessage()); } } } } } } return map; } catch (IOException e) { e.printStackTrace(); } return new HashMap<>(); }