List of usage examples for org.joda.time.format DateTimeFormatterBuilder DateTimeFormatterBuilder
public DateTimeFormatterBuilder()
From source file:ca.phon.session.DateFormatter.java
License:Open Source License
/** * Create a date formatter for {@link DateTime} objects. * //from w w w .j a v a 2 s . co m * @return formatter */ public static DateTimeFormatter createFormatter() { final DateTimeFormatter retVal = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral("-") .appendMonthOfYear(2).appendLiteral("-").appendDayOfMonth(2).toFormatter(); return retVal; }
From source file:ch.eitchnet.android.util.JodaHelper.java
License:Open Source License
/** * @param timestamp/* w w w . ja v a 2 s . c om*/ * @return */ public static String toHourMinute(ReadablePartial timestamp) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2); return builder.toFormatter().print(timestamp); }
From source file:ch.eitchnet.android.util.JodaHelper.java
License:Open Source License
/** * @param timestamp//from ww w . java 2 s . c o m * @return */ public static String toDateHourMinute(ReadablePartial timestamp) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.appendYear(4, 4).appendLiteral("-").appendMonthOfYear(2).appendLiteral("-").appendDayOfMonth(2); builder.appendLiteral(" ").appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2); return builder.toFormatter().print(timestamp); }
From source file:cherry.foundation.type.format.CustomDateTimeFormatAnnotationFormatterFactory.java
License:Apache License
private DateTimeFormatterBuilder builder(String pattern) { return new DateTimeFormatterBuilder().appendPattern(pattern); }
From source file:com.avid.central.obsplugin.inewslibrary.OBSRundown.java
public DateTime GetFileDate() { try {/*from w w w. j a v a2 s. co m*/ DateTimeParser[] parsers = { DateTimeFormat.forPattern("dd MMMM YYYY").getParser(), DateTimeFormat.forPattern("dd-MMMM-YYYY").getParser() }; DateTimeFormatter dtf = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateTime dt = DateTime.parse(Date, dtf); return dt; } catch (Exception ex) { String s = ex.getMessage(); } return new DateTime(0); }
From source file:com.bitlove.fetlife.util.DateUtil.java
License:Apache License
public static String toServerString(long time) { //2017-01-24 16:52:33.074 +0200' DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral('-') .appendMonthOfYear(2).appendLiteral('-').appendDayOfMonth(2).appendLiteral(' ').appendHourOfDay(2) .appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':').appendSecondOfMinute(2) .appendLiteral('.').appendMillisOfSecond(3).appendLiteral(' ') .appendTimeZoneOffset(null, false, 2, 2).toFormatter(); return dateTimeFormatter.print(time); }
From source file:com.clevercloud.bianca.lib.date.DateModule.java
License:Open Source License
/** * Returns the parsed date.//w w w . j a va 2s . c o m */ public Value strptime(Env env, String date, String format) { ArrayValueImpl array = new ArrayValueImpl(); DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder(); int length = format.length(); for (int i = 0; i < length; i++) { char ch = format.charAt(i); if (ch != '%') { fb.appendLiteral(ch); continue; } switch (format.charAt(++i)) { case 'a': fb.appendDayOfWeekShortText(); break; case 'A': fb.appendDayOfWeekText(); break; case 'h': case 'b': fb.appendMonthOfYearShortText(); ; break; case 'B': fb.appendMonthOfYearText(); break; // TODO: case 'c' case 'C': fb.appendCenturyOfEra(2, 2); break; case 'd': fb.appendDayOfMonth(2); break; case 'D': fb.appendMonthOfYear(2); fb.appendLiteral('/'); fb.appendDayOfMonth(2); fb.appendLiteral('/'); fb.appendYear(2, 2); break; // TODO: case 'e' case 'F': fb.appendYear(4, 4); fb.appendLiteral('-'); fb.appendMonthOfYear(2); fb.appendLiteral('-'); fb.appendDayOfMonth(2); break; // TODO: case 'g' // TODO: case 'G' case 'H': fb.appendHourOfDay(2); break; case 'I': fb.appendHourOfHalfday(2); break; case 'j': fb.appendDayOfYear(3); break; // TODO: case 'l' case 'm': fb.appendMonthOfYear(2); break; case 'M': fb.appendMinuteOfHour(2); break; case 'n': fb.appendLiteral("\n"); break; case 'p': case 'P': fb.appendHalfdayOfDayText(); break; case 'r': fb.appendHourOfHalfday(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); fb.appendLiteral(' '); fb.appendHalfdayOfDayText(); break; case 'R': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); break; // TODO: case 's' case 'S': fb.appendSecondOfMinute(2); break; case 't': fb.appendLiteral("\t"); break; case 'T': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); break; // TODO: case 'u' // TODO: case 'U' // TODO: case 'V' // TODO: case 'w' // TODO: case 'W' // TODO: case 'x' // TODO: case 'X' case 'y': fb.appendYear(2, 2); break; case 'Y': fb.appendYear(4, 4); break; case 'z': fb.appendTimeZoneOffset(null, true, 2, 2); break; case 'Z': fb.appendTimeZoneName(); break; case '%': fb.appendLiteral('%'); break; default: fb.appendLiteral(ch); } } DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed(); org.joda.time.DateTime dt = new org.joda.time.DateTime(); String unparsed = ""; try { dt = dtf.parseDateTime(date); } catch (IllegalArgumentException e) { String delims = "[\"]+"; String[] splits = e.getMessage().split(delims); unparsed = unparsed.concat(splits[3]); } // According to manual strptime(3) if (dt.getCenturyOfEra() == 0) { if (dt.getYear() > 68) { dt = dt.withCenturyOfEra(19); } else { dt = dt.withCenturyOfEra(20); } } array.put("tm_sec", dt.getSecondOfMinute()); array.put("tm_min", dt.getMinuteOfHour()); array.put("tm_hour", dt.getHourOfDay()); array.put("tm_mday", dt.getDayOfMonth()); array.put("tm_mon", dt.getMonthOfYear() - 1); array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900 array.put("tm_wday", dt.getDayOfWeek() % 7); array.put("tm_yday", dt.getDayOfYear() - 1); array.put("unparsed", unparsed); return array; }
From source file:com.enonic.cms.core.tools.plugin.PluginWrapper.java
License:Open Source License
public String getTimestamp() { return new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral('-').appendMonthOfYear(2) .appendLiteral('-').appendDayOfMonth(2).appendLiteral(' ').appendHourOfDay(2).appendLiteral(':') .appendMinuteOfHour(2).appendLiteral(':').appendSecondOfMinute(2).toFormatter() .print(this.plugin.getTimestamp()); }
From source file:com.facebook.presto.operator.scalar.DateTimeFunctions.java
License:Apache License
@SuppressWarnings("fallthrough") public static DateTimeFormatter createDateTimeFormatter(Slice format) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); String formatString = format.toString(Charsets.UTF_8); boolean escaped = false; for (int i = 0; i < format.length(); i++) { char character = formatString.charAt(i); if (escaped) { switch (character) { case 'a': // %a Abbreviated weekday name (Sun..Sat) builder.appendDayOfWeekShortText(); break; case 'b': // %b Abbreviated month name (Jan..Dec) builder.appendMonthOfYearShortText(); break; case 'c': // %c Month, numeric (0..12) builder.appendMonthOfYear(1); break; case 'd': // %d Day of the month, numeric (00..31) builder.appendDayOfMonth(2); break; case 'e': // %e Day of the month, numeric (0..31) builder.appendDayOfMonth(1); break; case 'f': // %f Microseconds (000000..999999) builder.appendMillisOfSecond(6); break; case 'H': // %H Hour (00..23) builder.appendHourOfDay(2); break; case 'h': // %h Hour (01..12) case 'I': // %I Hour (01..12) builder.appendClockhourOfHalfday(2); break; case 'i': // %i Minutes, numeric (00..59) builder.appendMinuteOfHour(2); break; case 'j': // %j Day of year (001..366) builder.appendDayOfYear(3); break; case 'k': // %k Hour (0..23) builder.appendClockhourOfDay(1); break; case 'l': // %l Hour (1..12) builder.appendClockhourOfHalfday(1); break; case 'M': // %M Month name (January..December) builder.appendMonthOfYearText(); break; case 'm': // %m Month, numeric (00..12) builder.appendMonthOfYear(2); break; case 'p': // %p AM or PM builder.appendHalfdayOfDayText(); break; case 'r': // %r Time, 12-hour (hh:mm:ss followed by AM or PM) builder.appendClockhourOfHalfday(2).appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':') .appendSecondOfMinute(2).appendLiteral(' ').appendHalfdayOfDayText(); break; case 'S': // %S Seconds (00..59) case 's': // %s Seconds (00..59) builder.appendSecondOfMinute(2); break; case 'T': // %T Time, 24-hour (hh:mm:ss) builder.appendHourOfDay(2).appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':') .appendSecondOfMinute(2); break; case 'v': // %v Week (01..53), where Monday is the first day of the week; used with %x builder.appendWeekOfWeekyear(2); break; case 'x': // %x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v builder.appendWeekyear(4, 4); break; case 'W': // %W Weekday name (Sunday..Saturday) builder.appendDayOfWeekText(); break; case 'w': // %w Day of the week (0=Sunday..6=Saturday) builder.appendDayOfWeek(1); break; case 'Y': // %Y Year, numeric, four digits builder.appendYear(4, 4); break; case 'y': // %y Year, numeric (two digits) builder.appendYearOfCentury(2, 2); break; case 'U': // %U Week (00..53), where Sunday is the first day of the week case 'u': // %u Week (00..53), where Monday is the first day of the week case 'V': // %V Week (01..53), where Sunday is the first day of the week; used with %X case 'X': // %X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V case 'D': // %D Day of the month with English suffix (0th, 1st, 2nd, 3rd, ) throw new PrestoException(INVALID_FUNCTION_ARGUMENT.toErrorCode(), String.format("%%%s not supported in date format string", character)); case '%': // %% A literal %? character builder.appendLiteral('%'); break; default: // %<x> The literal character represented by <x> builder.appendLiteral(character); break; }//from w ww . jav a 2 s. c o m escaped = false; } else if (character == '%') { escaped = true; } else { builder.appendLiteral(character); } } try { return builder.toFormatter(); } catch (UnsupportedOperationException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT.toErrorCode(), e); } }
From source file:com.facebook.presto.operator.scalar.UnixTimeFunctions.java
License:Apache License
@SuppressWarnings("fallthrough") public static DateTimeFormatter createDateTimeFormatter(Slice format) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); String formatString = format.toString(Charsets.UTF_8); boolean escaped = false; for (int i = 0; i < format.length(); i++) { char character = formatString.charAt(i); if (escaped) { switch (character) { case 'a': // %a Abbreviated weekday name (Sun..Sat) builder.appendDayOfWeekShortText(); break; case 'b': // %b Abbreviated month name (Jan..Dec) builder.appendMonthOfYearShortText(); break; case 'c': // %c Month, numeric (0..12) builder.appendMonthOfYear(1); break; case 'd': // %d Day of the month, numeric (00..31) builder.appendDayOfMonth(2); break; case 'e': // %e Day of the month, numeric (0..31) builder.appendDayOfMonth(1); break; case 'f': // %f Microseconds (000000..999999) builder.appendMillisOfSecond(6); break; case 'H': // %H Hour (00..23) builder.appendHourOfDay(2); break; case 'h': // %h Hour (01..12) case 'I': // %I Hour (01..12) builder.appendClockhourOfHalfday(2); break; case 'i': // %i Minutes, numeric (00..59) builder.appendMinuteOfHour(2); break; case 'j': // %j Day of year (001..366) builder.appendDayOfYear(3); break; case 'k': // %k Hour (0..23) builder.appendClockhourOfDay(1); break; case 'l': // %l Hour (1..12) builder.appendClockhourOfHalfday(1); break; case 'M': // %M Month name (January..December) builder.appendMonthOfYearText(); break; case 'm': // %m Month, numeric (00..12) builder.appendMonthOfYear(2); break; case 'p': // %p AM or PM builder.appendHalfdayOfDayText(); break; case 'r': // %r Time, 12-hour (hh:mm:ss followed by AM or PM) builder.appendClockhourOfHalfday(2).appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':') .appendSecondOfMinute(2).appendLiteral(' ').appendHalfdayOfDayText(); break; case 'S': // %S Seconds (00..59) case 's': // %s Seconds (00..59) builder.appendSecondOfMinute(2); break; case 'T': // %T Time, 24-hour (hh:mm:ss) builder.appendHourOfDay(2).appendLiteral(':').appendMinuteOfHour(2).appendLiteral(':') .appendSecondOfMinute(2); break; case 'v': // %v Week (01..53), where Monday is the first day of the week; used with %x builder.appendWeekOfWeekyear(2); break; case 'W': // %W Weekday name (Sunday..Saturday) builder.appendDayOfWeekText(); break; case 'w': // %w Day of the week (0=Sunday..6=Saturday) builder.appendDayOfWeek(1); break; case 'Y': // %Y Year, numeric, four digits builder.appendYear(4, 4); break; case 'y': // %y Year, numeric (two digits) builder.appendYearOfCentury(2, 2); break; case 'U': // %U Week (00..53), where Sunday is the first day of the week case 'u': // %u Week (00..53), where Monday is the first day of the week case 'V': // %V Week (01..53), where Sunday is the first day of the week; used with %X case 'X': // %X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V case 'x': // %x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v case 'D': // %D Day of the month with English suffix (0th, 1st, 2nd, 3rd, ) throw new UnsupportedOperationException( String.format("%%%s not supported in date format string", character)); case '%': // %% A literal %? character builder.appendLiteral('%'); break; default: // %<x> The literal character represented by <x> builder.appendLiteral(character); break; }/*from w ww .j a v a 2 s .c om*/ escaped = false; } else if (character == '%') { escaped = true; } else { builder.appendLiteral(character); } } return builder.toFormatter(); }