Java Code Examples for org.joda.time.format.ISODateTimeFormat#dateTimeNoMillis()

The following examples show how to use org.joda.time.format.ISODateTimeFormat#dateTimeNoMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Serializer.java    From omise-java with MIT License 8 votes vote down vote up
private Serializer() {
    dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis();
    localDateFormatter = ISODateTimeFormat.date();

    objectMapper = new ObjectMapper()
            .registerModule(new JodaModule()
                    .addSerializer(DateTime.class, new DateTimeSerializer()
                            .withFormat(new JacksonJodaDateFormat(dateTimeFormatter), 0)
                    )
                    .addSerializer(LocalDate.class, new LocalDateSerializer()
                            .withFormat(new JacksonJodaDateFormat(localDateFormatter), 0)
                    )
            )

            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // TODO: Deprecate in vNext
}
 
Example 2
Source File: PrimitiveColumnMetadata.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public DateTimeFormatter dateTimeFormatter() {
  String formatValue = format();
  try {
    switch (type) {
      case TIME:
        return formatValue == null
          ? ISODateTimeFormat.localTimeParser() : DateTimeFormat.forPattern(formatValue);
      case DATE:
        formatValue = format();
        return formatValue == null
          ? ISODateTimeFormat.localDateParser() : DateTimeFormat.forPattern(formatValue);
      case TIMESTAMP:
        formatValue = format();
        return formatValue == null
          ? ISODateTimeFormat.dateTimeNoMillis() : DateTimeFormat.forPattern(formatValue);
      default:
        throw new IllegalArgumentException("Column is not a date/time type: " + type.toString());
    }
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(String.format("The format \"%s\" is not valid for type %s",
        formatValue, type), e);
  }
}
 
Example 3
Source File: JodaLocalDateTimeCodec.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
protected DateTimeFormatter isoFormatter() {
    return ISODateTimeFormat.dateTimeNoMillis();
}
 
Example 4
Source File: ModelUtil.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
public static Date stringToDate(String dateString){
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    return fmt.parseDateTime(dateString).toDate();
}
 
Example 5
Source File: ModelUtil.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
public static String dateToString(Date date){
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dateTime = new DateTime(date);
    return fmt.print(dateTime);
}