List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:com.facebook.presto.teradata.functions.TeradataDateFunctions.java
License:Apache License
@Description("Formats a timestamp") @ScalarFunction("to_char") @SqlType(StandardTypes.VARCHAR)/*from ww w . ja v a2 s .com*/ public static Slice toChar(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone, @SqlType(StandardTypes.VARCHAR) Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString) .withChronology(CHRONOLOGIES[unpackZoneKey(timestampWithTimeZone).getKey()]) .withLocale(session.getLocale()); return utf8Slice(formatter.print(unpackMillisUtc(timestampWithTimeZone))); }
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>// w ww. j av a 2 s .com * * 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.DateTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p>// www . ja v a 2 s. 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.LocalDateConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p>// w w w. j a v a 2 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(LocalDate src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return new JsonPrimitive(fmt.print(src)); }
From source file:com.fatboyindustrial.gsonjodatime.LocalDateTimeConverter.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 v a2s.c om*/ * * 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(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return new JsonPrimitive(fmt.print(src)); }
From source file:com.fatboyindustrial.gsonjodatime.LocalTimeConverter.java
License:Open Source License
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p>//from w w w . j av a 2 s . com * * 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(LocalTime src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return new JsonPrimitive(fmt.print(src)); }
From source file:com.forecast.io.v2.transfer.DataPoint.java
License:Apache License
/** (Added by Androidsx.) */ @Override//from ww w. j a v a2 s .co m public String toString() { final DateTimeFormatter debugDateTimeFormatter = new DateTimeFormatterBuilder().appendDayOfWeekShortText() .appendLiteral(", ").appendMonthOfYearShortText().appendLiteral(" ").appendDayOfMonth(2) .appendLiteral(" at ").appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2) .appendLiteral(":").appendSecondOfMinute(2).toFormatter().withLocale(Locale.US); return "[" + debugDateTimeFormatter.print(getTime() * 1000) + "] " + "\"" + getIcon() + "\", " + "(temp: " + getTemperature() + ")"; }
From source file:com.github.flawedbliss.dicebotr3.DicebotR3.java
License:Open Source License
private void updateLastlogin(String uid) { Connection connect = null;/* www .j av a2 s .c o m*/ PreparedStatement preparedStatement = null; PreparedStatement preparedStatement2 = null; ResultSet resultSet = null; DateTime date = new DateTime(new Date()); DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); try { connect = cp.getConnection(); preparedStatement = connect.prepareStatement("SELECT * FROM lastlogin WHERE uid=?"); preparedStatement.setString(1, uid); resultSet = preparedStatement.executeQuery(); if (resultSet.isBeforeFirst()) { preparedStatement2 = connect.prepareStatement("UPDATE lastlogin SET lastlogin=? WHERE " + "uid=?"); preparedStatement2.setString(1, dtf.print(date)); preparedStatement2.setString(2, uid); preparedStatement2.executeUpdate(); } else { preparedStatement2 = connect .prepareStatement("INSERT INTO lastlogin (uid, lastlogin)" + " VALUES (?, ?)"); preparedStatement2.setString(1, uid); preparedStatement2.setString(2, dtf.print(date)); preparedStatement2.executeUpdate(); } preparedStatement2.close(); resultSet.close(); preparedStatement.close(); connect.close(); } catch (SQLException ex) { log.warning("SQLException when trying to update lastlogin of " + uid); } }
From source file:com.github.flawedbliss.dicebotr3.DicebotR3.java
License:Open Source License
private boolean addNotice(Notice notice) { Connection connect = null;//from w w w. j a v a2s.co m PreparedStatement preparedStatement = null; DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); try { connect = cp.getConnection(); preparedStatement = connect.prepareStatement("INSERT INTO " + cfg.getMysqlNoticeTable() + "(message, expirationDate, special) VALUES (?, ?, ?)"); preparedStatement.setString(1, notice.getMessage()); preparedStatement.setString(2, dtf.print(notice.getExpirationDate())); preparedStatement.setBoolean(3, notice.isSpecial()); preparedStatement.executeUpdate(); preparedStatement.close(); connect.close(); return true; } catch (SQLException ex) { log.warning("SQLException while trying to add a new notice."); return false; } }
From source file:com.github.flawedbliss.dicebotr4.MySqlManager.java
License:Open Source License
/** * * @param uid Unique ID of the user whose lastlogin entry should be * added/updated//from ww w. ja v a2 s . com * @throws DicebotException */ public void updateLastLogin(String uid) throws DicebotException { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); try (Connection connect = cp.getConnection()) { String sql; PreparedStatement statement; DateTime now = new DateTime(new Date()); DateTime lastlogin = getLastLogin(uid); if (lastlogin == null) { sql = "INSERT INTO lastlogin (uid, lastlogin) VALUES (?, ?)"; statement = connect.prepareStatement(sql); statement.setString(0, uid); statement.setString(1, dtf.print(now)); statement.executeUpdate(); } else { sql = "UPDATE lastlogin SET lastlogin=? WHERE uid=?"; statement = connect.prepareStatement(sql); statement.setString(0, dtf.print(now)); statement.setString(1, uid); statement.executeUpdate(); } statement.close(); } catch (SQLException ex) { throw new DicebotException("Could not insert/update lastlogin for " + uid + " . Ignoring."); } }