List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:com.code2040.bofashola.DatingGame.java
private static String getISO(String dateStamp, long seconds) { String str = ""; //parse the datestamp string String date = dateStamp.split("T")[0]; String time = dateStamp.split("T")[1]; int year = Integer.valueOf(date.split("-")[0]); int month = Integer.valueOf(date.split("-")[1]); int dat = Integer.valueOf(date.split("-")[2]); int hrs = Integer.valueOf(time.split(":")[0]); int minute = Integer.valueOf(time.split(":")[1]); String secTemp = (time.split(":")[2]); int sec = Integer.valueOf(secTemp.charAt(0) + "" + secTemp.charAt(1)); DateTime dt = new DateTime(year, month, dat, hrs, minute, sec); //Convert the string to milliseconds and add the interval in milliseconds long timeInMills = dt.getMillis() + getMilliseconds(seconds); DateTime newtime = new DateTime(timeInMills); //Use the Joda Time API and change it to ISO 8061 format DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); str = fmt.print(newtime);/*from w w w. j a v a 2s. c o m*/ return str.replace(str.substring(23, str.length()), "Z"); }
From source file:com.einzig.ipst2.util.LogEntry.java
License:Open Source License
@Override public String toString() { return "[" + ISODateTimeFormat.dateTime().print(time) + "] " + level + "/" + scope + ": " + message + "\n"; }
From source file:com.facebook.presto.kudu.properties.KuduTableProperties.java
License:Apache License
private static Object toValue(Schema schema, PartialRow bound, Integer idx) { Type type = schema.getColumnByIndex(idx).getType(); switch (type) { case UNIXTIME_MICROS: long millis = bound.getLong(idx) / 1000; return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC).print(millis); case STRING://from w w w . j a v a2s . com return bound.getString(idx); case INT64: return bound.getLong(idx); case INT32: return bound.getInt(idx); case INT16: return bound.getShort(idx); case INT8: return (short) bound.getByte(idx); case BOOL: return bound.getBoolean(idx); case BINARY: return bound.getBinaryCopy(idx); default: throw new IllegalStateException("Unhandled type " + type + " for range partition"); } }
From source file:com.fatboyindustrial.gsonjodatime.DateMidnightConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p>//from ww w. j a va2 s . co m * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any * non-trivial field of the {@code src} object. However, you should never invoke it on the * {@code src} object itself since that will cause an infinite loop (Gson will call your * call-back method again). * * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(DateMidnight src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return new JsonPrimitive(fmt.print(src)); }
From source file:com.fatboyindustrial.gsonjodatime.DateMidnightConverter.java
License:Open Source License
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p>/*from w w w.j a va 2 s .c o m*/ * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonDeserializationContext#deserialize(com.google.gson.JsonElement, java.lang.reflect.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 com.google.gson.JsonParseException if json is not in the expected format of {@code typeOfT} */ @Override public DateMidnight deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return new DateMidnight(fmt.parseDateTime(json.getAsString())); }
From source file:com.fatboyindustrial.gsonjodatime.DateTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p>// ww w . j a v a 2s . c o m * * In the implementation of this call-back method, you should consider invoking * {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any * non-trivial field of the {@code src} object. However, you should never invoke it on the * {@code src} object itself since that will cause an infinite loop (Gson will call your * call-back method again). * * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return new JsonPrimitive(fmt.print(src)); }
From source file:com.fatboyindustrial.gsonjodatime.DateTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p>/*from w ww.ja va 2s .com*/ * * 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 DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.parseDateTime(json.getAsString()); }
From source file:com.fatminds.cmis.AlfrescoCmisHelper.java
License:Apache License
/** * Try several different date formats (in order of descending specificity) to parse a potential * date string.//from w w w. j av a 2s. c o m * @param inVal * @return * @throws IllegalArgumentException if the string cannot be successfully parsed into a date. */ public static GregorianCalendar attemptDateParse(String inVal) { if (null == inVal || inVal.length() < 1) throw new IllegalArgumentException("Cannot parse null date/time string"); // Attempt formats in order of reducing specificity try { DateTime d = ISODateTimeFormat.dateTime().parseDateTime(inVal); return d.toGregorianCalendar(); } catch (IllegalArgumentException e) { try { LocalDate d = DateTimeFormat.forPattern("yyyy-MM-dd").parseLocalDate(inVal); return d.toDateTimeAtMidnight().toGregorianCalendar(); } catch (IllegalArgumentException e2) { try { LocalDate d = DateTimeFormat.forPattern("MM/dd/yyyy").parseLocalDate(inVal); return d.toDateTimeAtMidnight().toGregorianCalendar(); } catch (IllegalArgumentException e3) { try { LocalDate d = DateTimeFormat.forPattern("MM/dd/yy").parseLocalDate(inVal); return d.toDateTimeAtMidnight().toGregorianCalendar(); } catch (IllegalArgumentException e4) { } } } } log.error("Cannot parse date/time string " + inVal); throw new IllegalArgumentException("Cannot parse date/time string " + inVal); }
From source file:com.getperka.flatpack.codexes.DateCodex.java
License:Apache License
@Override public void writeNotNull(D object, SerializationContext context) throws Exception { String value = ISODateTimeFormat.dateTime().print(object.getTime()); context.getWriter().value(value);/*from ww w. j av a2 s . c o m*/ }
From source file:com.github.autermann.matlab.json.MatlabValueSerializer.java
License:Open Source License
private MatlabDateTime parseMatlabDateTime(JsonElement value) { DateTime dt = ISODateTimeFormat.dateTime().parseDateTime(value.getAsString()); return new MatlabDateTime(dt); }