List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.none.tom.simplerssreader.opml.OPMLParser.java
License:Open Source License
private static DateTime validateDateTime(final XmlPullParser parser, final String version, final String... element) throws OPMLParserException, XmlPullParserException, IOException { final String value; if (element.length > 0) { value = parser.getAttributeValue(null, element[0]); } else {//from www. j a v a2 s . c o m value = XmlPullParserUtils.getText(parser); } if (!TextUtils.isEmpty(value)) { if (version.equals("1.0") || version.equals("1.1")) { try { return DateTimeFormat.forPattern(RFC_822_EXTENDED[1]).parseDateTime(value); } catch (final IllegalArgumentException e) { throw new OPMLParserException(parser); } } else { for (final String pattern : RFC_822_EXTENDED) { try { return DateTimeFormat.forPattern(pattern).parseDateTime(value); } catch (final IllegalArgumentException ignored) { } } throw new OPMLParserException(parser); } } return null; }
From source file:com.norconex.jefmon.instance.tree.DateStartedColumn.java
License:Apache License
private String getTimeString(Date date) { if (date == null) { return StringUtils.EMPTY; }/*from w ww . j a va2 s . c o m*/ Locale locale = JEFMonSession.getSession().getLocale(); String pattern = "yyyy-MMM-dd - H:mm:ss"; return DateTimeFormat.forPattern(pattern).withLocale(locale).print(date.getTime()); }
From source file:com.oneops.search.msg.processor.CIMessageProcessor.java
License:Apache License
private static void convertIllegalDateFormat(Map<String, String> ciAttributes, String name) { if (ciAttributes != null && ciAttributes.containsKey(name)) { String date = ciAttributes.get(name); //Nov 5 21:08:38 2019 GMT //Jan 22 18:21:47 2020 GMT // Some of the `expires_one` date fields apparently have date format with two spaces, so while this conversion is a hack, // until we migrate to newer ES version and change the mapping we need to accommodate both, since single DateTimeFormat can't handle it. DateTimeFormatter wrongFormat = DateTimeFormat.forPattern("MMM dd HH:mm:ss yyyy z"); DateTimeFormatter wrongFormat2 = DateTimeFormat.forPattern("MMM dd HH:mm:ss yyyy z"); /// 2020-01-22T18:21:47 DateTimeFormatter rightFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss"); try {//from ww w. j a v a 2s .com ciAttributes.put(name, rightFormat.print(wrongFormat.parseMillis(date))); } catch (Exception e) { try { ciAttributes.put(name, rightFormat.print(wrongFormat2.parseMillis(date))); } catch (Exception ignore) { // do nothing, unexpected date format } } } }
From source file:com.passwordboss.android.analytics.AnalyticsHelperSegment.java
public static boolean checkTime(Context mContext, String item) { String storedDate = ""; boolean sendData = false; if (Pref.SEGMENT_FLUSH.equals(item)) { storedDate = Pref.getValue(mContext, Pref.SEGMENT_FLUSH, ""); } else if (Constants.ACTIVE_USER_ANALYTIC.equals(item)) { storedDate = Pref.getValue(mContext, Constants.ACTIVE_USER_ANALYTIC, ""); }/*from ww w.j av a2s . co m*/ if (storedDate.length() > 0) { DateTime d1 = DateTime.now(); DateTime d2 = DateTime.parse(storedDate, DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss")); long diff = d1.getMillis() - d2.getMillis(); if (diff > diff) { // // TODO: 3/4/2016 figure out what would be implemented there sendData = true; } } else { sendData = true; } return sendData; }
From source file:com.payintech.smoney.toolbox.JodaDateTimeConverter.java
License:Open Source License
/** * Build a converter instance with a specific format. * * @param pattern Pattern respecting the {@code Joda.DateTimeFormatter} syntax. * @see DateTimeFormatter/*from ww w .j av a2 s . c o m*/ * @since 15.11 */ public JodaDateTimeConverter(final String pattern) { this.formatter = DateTimeFormat.forPattern(pattern); this.isoFormatter = ISODateTimeFormat.dateTime(); }
From source file:com.pipit.agc.util.LocalDateTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p>/*from ww w .j av a 2s. c o m*/ * * In the implementation of this call-back method, you should consider invoking * {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects * for any non-trivial field of the returned object. However, you should never invoke it on the * the same type passing {@code json} since that will cause an infinite loop (Gson will call your * call-back method again). * @param json The Json data being deserialized * @param typeOfT The type of the Object to deserialize to * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T} * @throws JsonParseException if json is not in the expected format of {@code typeOfT} */ @Override public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // Do not try to deserialize null or empty values if (json.getAsString() == null || json.getAsString().isEmpty()) { return null; } final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return fmt.parseLocalDateTime(json.getAsString()); }
From source file:com.pokescanner.MapsActivity.java
License:Open Source License
public String getTimeEstimate(int val) { int calculatedValue = hexagonal_number(val) * SettingsController.getSettings(this).getServerRefresh() * 1000;/*from w w w. j a v a 2 s . c om*/ long millis = calculatedValue; DateTime dt = new DateTime(millis); DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss"); return fmt.print(dt); }
From source file:com.pokescanner.objects.Pokemons.java
License:Open Source License
public MarkerOptions getMarker(Context context, int scale) { String uri = "p" + getNumber(); int resourceID = context.getResources().getIdentifier(uri, "drawable", context.getPackageName()); Interval interval;/*from ww w .j a va2 s.com*/ //Find our interval interval = new Interval(new Instant(), getDate()); //turn our interval into MM:SS DateTime dt = new DateTime(interval.toDurationMillis()); DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss"); String timeOut = fmt.print(dt); //set our location LatLng position = new LatLng(getLatitude(), getLongitude()); Bitmap out = DrawableUtils.writeTextOnDrawable(resourceID, timeOut, scale, context); String name = getName(); name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); MarkerOptions pokeIcon = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(out)) .position(position).title(name).snippet(timeOut); return pokeIcon; }
From source file:com.popdeem.sdk.uikit.utils.PDUIUtils.java
License:Open Source License
/** * Format a Unix Time stamp for the given format * * @param date Unix Time stamp in seconds * @param format Format to use when converting. * @return Formatted date String/* w ww. j a v a2s . c o m*/ */ public static String convertUnixTimeToDate(long date, String format) { DateTime dateTime = new DateTime(date * 1000); DateTimeFormatter formatter = DateTimeFormat.forPattern(format); return formatter.print(dateTime); }
From source file:com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler.AbstractFXTweetHandler.java
License:Apache License
private void setStartTimeAsStr() { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); startTimeAsStr = formatter.print(this.startTime); }