Java 8 DateTimeFormatter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DateTimeFormatter class.

This code example shows how to use the following methods:withLocale
 
	@Override 
	public TemporalAccessor parse(String text, Locale locale) throws ParseException {
		DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
		if (LocalDate.class.equals(this.temporalAccessorType)) {
			return LocalDate.parse(text, formatterToUse);
		} 
		else if (LocalTime.class.equals(this.temporalAccessorType)) {
			return LocalTime.parse(text, formatterToUse);
		} 
		else if (LocalDateTime.class.equals(this.temporalAccessorType)) {
			return LocalDateTime.parse(text, formatterToUse);
		} 
		else if (ZonedDateTime.class.equals(this.temporalAccessorType)) {
			return ZonedDateTime.parse(text, formatterToUse);
		} 
		else if (OffsetDateTime.class.equals(this.temporalAccessorType)) {
			return OffsetDateTime.parse(text, formatterToUse);
		} 
		else if (OffsetTime.class.equals(this.temporalAccessorType)) {

7
CodeRank
This code example shows how to use the following methods:withChronology, withZone
	 * formatting rules, generally context-independent 
	 * @return the contextual DateTimeFormatter 
	 */ 
	public DateTimeFormatter getFormatter(DateTimeFormatter formatter) {
		if (this.chronology != null) {
			formatter = formatter.withChronology(this.chronology);
		} 
		if (this.timeZone != null) {
			formatter = formatter.withZone(this.timeZone);
		} 
		else { 
			LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
			if (localeContext instanceof TimeZoneAwareLocaleContext) {
				TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
				if (timeZone != null) {
					formatter = formatter.withZone(timeZone.toZoneId());
				} 
			} 
		} 
		return formatter;
7
CodeRank
This code example shows how to use the following methods:withLocale
	 * (generally user independent) 
	 * @param locale the current user locale (may be {@code null} if not known) 
	 * @return the user-specific DateTimeFormatter 
	 */ 
	public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
		DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
		DateTimeContext context = getDateTimeContext();
		return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:withZone
                    dtf = DateTimeFormatter.ofPattern(pattern, locale);
                } 
                //Issue #69: For instant serializers/deserializers we need to configure the formatter with 
                //a time zone picked up from JsonFormat annotation, otherwise serialization might not work 
                if (format.hasTimeZone()) {
                    dtf = dtf.withZone(format.getTimeZone().toZoneId());
                } 
            } 
            JSR310FormattedSerializerBase<?> ser = this;
            if ((useTimestamp != _useTimestamp) || (dtf != _formatter)) {
                ser = ser.withFormat(useTimestamp, dtf);
            } 
            Boolean writeZoneId = format.getFeature(JsonFormat.Feature.WRITE_DATES_WITH_ZONE_ID);
            if (writeZoneId != null) {
                ser = ser.withFeatures(writeZoneId);
            } 
            return ser;
        } 
        return this;
    } 
4
CodeRank
This code example shows how to use the following methods:withZone
            if (v2 != null) {
                v2.numberType(NumberType.BIG_DECIMAL);
            } 
        } else { 
            JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
            if (v2 != null) {
                v2.numberType(NumberType.LONG);
            } 
        } 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:withZone
This code example shows how to use the following methods:withZone
This code example shows how to use the following methods:withZone
This code example shows how to use the following methods:withZone
This code example shows how to use the following methods:withZone
See Code Examples for Java 8 DateTimeFormatter Methods: