Java 8 LocalDate - 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 LocalDate class.

This code example shows how to use the following methods:format, getDayOfMonth, getMonthValue, getYear, toString
    @Override 
    public void serialize(LocalDate date, JsonGenerator generator, SerializerProvider provider) throws IOException
    { 
        if (useTimestamp(provider)) {
            generator.writeStartArray();
            generator.writeNumber(date.getYear());
            generator.writeNumber(date.getMonthValue());
            generator.writeNumber(date.getDayOfMonth());
            generator.writeEndArray();
        } else { 
            String str = (_formatter == null) ? date.toString() : date.format(_formatter);
            generator.writeString(str);
        } 
    } 
     
    @Override 
    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
    { 
        SerializerProvider provider = visitor.getProvider();
        boolean useTimestamp = (provider != null) && useTimestamp(provider);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getDayOfMonth, getMonthValue
    this.year = year;
  } 
 
  private MonthDay convertFromDate(Date ts) {
    LocalDate localDate = ts.toLocalDate();
    return MonthDay.of(localDate.getMonthValue(), localDate.getDayOfMonth());
  } 
 
  private Date convertToDate(MonthDay value) {
    return Date.valueOf(LocalDate.of(2000, value.getMonthValue(), value.getDayOfMonth()));
  } 
 
  @Override 
  public MonthDay read(DataReader dataReader) throws SQLException {
    Date ts = dataReader.getDate();
    return ts == null ? null : convertFromDate(ts);
  } 
 
 
  @Override 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:atStartOfDay, plusDays
        List<Logs> list = null;
        if (logged) {
            LocalDate start = date == null
                              ? LocalDate.now()
                              : date.toLocalDate();
            LocalDate tomorrow = start.plusDays(1);
            LogsCriteria criteria = new LogsCriteria(ds);
            criteria.channel(channelName);
            LocalDateTime nextMidnight = tomorrow.atStartOfDay();
            LocalDateTime lastMidnight = start.atStartOfDay();
            criteria.and(
                            criteria.updated().lessThanOrEq(nextMidnight),
                            criteria.updated().greaterThanOrEq(lastMidnight)
                        ); 
            list = criteria.query().asList();
        } 
        return list;
    } 
 
    public List<Logs> findByChannel(String name, LocalDateTime date, Boolean showAll) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:atStartOfDay
    } 
 
    @Override 
    public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException {
        if (value != null) {
            statement.setTimestamp(position, Timestamp.valueOf(value.atStartOfDay()));
        } else { 
            statement.setNull(position, Types.TIMESTAMP);
        } 
    } 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:toString
	@JsonSerialize(using = LocalDateSerializer.class) 
	private LocalDate dob;
 
	public Object[] toArray() { 
		return new Object[] { id, lastName, firstName, street, zip, city, country, lat, 
				lng, email, dob.toString() }; 
	} 
 
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<>();
		map.put("id", id);
		map.put("lastName", lastName);
		map.put("firstName", firstName);
		map.put("street", street);
		map.put("zip", zip);
		map.put("city", city);
		map.put("country", country);
		map.put("lat", lat);
		map.put("lng", lng);
		map.put("email", email);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:atStartOfDay
  } 
 
  @Override 
  public long convertToMillis(YearMonth value) {
    LocalDate localDate = toLocalDate(value);
    ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
    return zonedDateTime.toInstant().toEpochMilli();
  } 
 
  @Override 
  public YearMonth convertFromDate(Date ts) {
    return fromLocalDate(ts.toLocalDate());
  } 
 
  @Override 
  public Date convertToDate(YearMonth t) {
    return Date.valueOf(toLocalDate(t));
  } 
 
  @Override 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:toString
        return localDate;
    } 
 
    @Override 
    public String toNonNullString(LocalDate value) {
        return value.toString();
    } 
 
    @Override 
    public Date toNonNullValue(LocalDate value) {
    	 
        if (getDatabaseZone() == null) { 
        	return Date.valueOf(LOCAL_DATE_FORMATTER.format((LocalDate) value));
        } 
    	 
		ZoneOffset currentDatabaseZone = getDatabaseZone() == null ? getDefault() : getDatabaseZone();
    	ZonedDateTime zonedValue = value.atStartOfDay(currentDatabaseZone);
 
//        Instant valueAsInstant = Instant.ofEpochSecond(zonedValue.toEpochSecond()); 
//        int defaultTimezoneOffset = TimeZone.getDefault().getOffset(zonedValue.toEpochSecond() * MILLIS_IN_SECOND); 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:toString
				throw new MessageTypeException("Attempted to write null"); 
			} 
			pk.writeNil();
			return; 
		} 
		pk.write(target.toString());
	} 
 
	@Override 
	public LocalDate read(Unpacker u, LocalDate to, boolean required) throws IOException {
		if (!required && u.trySkipNil()) {
			return null; 
		} 
		String temp = u.readString();
		return LocalDate.parse(temp);
	} 
 
	static public LocalDateTemplate getInstance() { 
		return instance;
	} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:toString
public class LocalDateSerializer extends JsonSerializer<LocalDate> {
 
	@Override 
	public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider)
			throws IOException, JsonProcessingException {
		jgen.writeString(value.toString());
	} 
 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:plusDays
    } 
 
    @Override 
    public Object decodeBinary(Connection con, ColumnInfo field, ByteBuffer buf, int colSize) throws IOException {
        int days = buf.getInt();
        return PG_DATE_BASE.plusDays(days);
    } 
 
    @Override 
    protected Object convertParsed(Connection con, TemporalAccessor temporal) {
        return LocalDate.from(temporal);
    } 
} 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 LocalDate Methods: