List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) { String twitterSearch = "http://search.twitter.com/search.json?q=" + tag; ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid // with this formatter SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); try {//from w w w .j a va 2 s . com Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon); JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("results"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url")); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("created_at")); } catch (ParseException e) { Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at")); e.printStackTrace(); } String user = jsonItem.getString("from_user"); SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"), formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str"); newItem.setLink(link); socialItems.add(newItem); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return socialItems; }
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) { String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key=" + Config.PLUS_KEY;//from ww w. j av a2 s. c om Log.d("SUSEConferences", "Google search: " + twitterSearch); ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon); try { JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("items"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); JSONObject actorItem = jsonItem.getJSONObject("actor"); JSONObject imageItem = actorItem.getJSONObject("image"); JSONObject objectItem = jsonItem.getJSONObject("object"); Bitmap image = HTTPWrapper.getImage(imageItem.getString("url")); String content = Html.fromHtml(objectItem.getString("content")).toString(); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("published")); } catch (ParseException e) { e.printStackTrace(); } SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content, formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); newItem.setLink(jsonItem.getString("url")); socialItems.add(newItem); } } catch (IllegalStateException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return socialItems; }
From source file:com.amazonaws.util.JodaTime.java
private static boolean checkFormatRfc822Date() throws ParseException { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); String expected = sdf.format(date); String actual = DateUtils.rfc822DateFormat.print(date.getTime()); if (expected.equals(actual)) { Date expectedDate = sdf.parse(expected); Date actualDate2 = new Date(DateUtils.rfc822DateFormat.parseMillis(actual)); return expectedDate.equals(actualDate2); }/*from w w w . j a v a2 s . c o m*/ return false; }
From source file:mk.finki.ranggo.aggregator.Aggregator.java
private static void update(String date, ContentsAggregator aggregator) { //if 'date' is null, the method aggregates contents published on the current date //if it is, it aggregates the data published on that date //parameter format is dd.mm.yyyy, assumed UTC+0 //parse or generate date object Date dateObj = null;/*from w w w. j a va2 s .c o m*/ if (date != null) { try { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.mm.yyyy"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dateObj = simpleDateFormat.parse(date); } catch (ParseException e) { } } else { //no date parameter, default case is today Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); dateObj = calendar.getTime(); } if (dateObj != null) { try { aggregator.aggregateGoogleNewsRSSFeed(dateObj); } catch (ContentsAggregatorException exception) { //log this } try { aggregator.aggregateHuffingtonPost(); } catch (ContentsAggregatorException exception) { //log this } try { aggregator.aggregateDnevnik(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateKurir(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateLibertas(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateNovaTV(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateRepublika(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateTelma(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateUtrinskiVesnik(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVecher(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVest(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateVesti24(); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateNYTimes(dateObj); } catch (ContentsAggregatorException exception) { } try { aggregator.aggregateTheGuardian(dateObj); } catch (ContentsAggregatorException exception) { } } }
From source file:com.appsimobile.appsii.module.weather.loader.WeatherDataParser.java
public static void parseWeatherData(CircularArray<WeatherData> result, String jsonString, CircularArray<String> woeids) throws JSONException, ResponseParserException, ParseException { if (woeids.isEmpty()) return;//from ww w . j a v a2s . com SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US); simpleDateFormat.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC)); SimpleJson json = new SimpleJson(jsonString); // when only a single woeid was requested, this is an object, otherwise it is an array. // So we need to check if we got an array; if so, handle each of the objects. // Otherwise get it as an object JSONArray resultsArray = json.getJsonArray("query.results.channel"); if (resultsArray == null) { JSONObject weatherObject = json.optJsonObject("query.results.channel"); if (weatherObject == null) return; String woeid = woeids.get(0); WeatherData weatherData = parseWeatherData(woeid, simpleDateFormat, weatherObject); if (weatherData != null) { result.addLast(weatherData); } return; } int length = resultsArray.length(); for (int i = 0; i < length; i++) { JSONObject weatherJson = resultsArray.getJSONObject(i); WeatherData weatherData = parseWeatherData(woeids.get(i), simpleDateFormat, weatherJson); if (weatherData == null) continue; result.addLast(weatherData); } }
From source file:DateUtils.java
public static final String getCurrentDate(String format) { Calendar cal = Calendar.getInstance(TimeZone.getDefault()); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getDefault()); return (sdf.format(cal.getTime())); }
From source file:DateUtils.java
public static final String formatDate(Date dt, String format) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dt);/*from w w w .j ava2 s.c om*/ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getDefault()); return (sdf.format(cal.getTime())); }
From source file:io.ignitr.dispatchr.manager.domain.subscription.FindSubscriptionsResponse.java
/** * * @param metadatas//from w w w .ja v a2 s. c o m * @return */ public static FindSubscriptionsResponse from(List<Subscription> metadatas) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); FindSubscriptionsResponse response = new FindSubscriptionsResponse(); metadatas.forEach(metadata -> { Result result = new Result(); result.setSubscriptionId(metadata.getId()); result.setClientId(metadata.getClientId()); result.setTopic(metadata.getTopicName()); result.setTopicArn(metadata.getTopicArn()); result.setQueueArn(metadata.getQueueArn()); result.setCreateDate(sdf.format(new Date(metadata.getCreateDate()))); result.setLastSubscribeDate(sdf.format(new Date(metadata.getLastSubscribeDate()))); result.add(linkTo(methodOn(TopicController.class).findOne(metadata.getTopicName(), null)) .withRel("topic")); response.addResult(result); }); return response; }
From source file:ddf.catalog.transformer.metacard.propertyjson.PropertyJsonMetacardTransformer.java
@Nullable private static Object convertValue(String name, Serializable value, AttributeType.AttributeFormat format) throws CatalogTransformerException { if (value == null) { return null; }/* w ww . j a v a2s .c om*/ switch (format) { case DATE: if (!(value instanceof Date)) { LOGGER.debug("Dropping attribute date value {} for {} because it isn't a Date object.", value, name); return null; } // Creating date format instance each time is inefficient, however // it is not a threadsafe class so we are not able to put it in a static // class variable. If this proves to be a slowdown this class should be refactored // such that we don't need this method to be static. SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_8601_DATE_FORMAT); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format((Date) value); case BINARY: byte[] bytes = (byte[]) value; return DatatypeConverter.printBase64Binary(bytes); case BOOLEAN: case DOUBLE: case LONG: case INTEGER: case SHORT: return value; case STRING: case XML: case FLOAT: case GEOMETRY: return value.toString(); case OBJECT: default: return null; } }
From source file:com.vangent.hieos.xutil.hl7.date.Hl7Date.java
/** * Convert a Java date to HL7 format./*from w w w. j a v a 2 s.c o m*/ * * @param date Java date. * @return String In HL7 format. */ static public String toHL7format(Date date) { String hl7DateFormat = "yyyyMMdd"; SimpleDateFormat formatter = new SimpleDateFormat(hl7DateFormat); Calendar c = Calendar.getInstance(); c.setTime(date); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); String hl7formattedDate = formatter.format(date); hl7formattedDate.replaceAll("UTC", "Z"); return hl7formattedDate; }