Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime withDayOfYear(int dayOfYear)
Returns a copy of this OffsetDateTime with the day-of-year replaced with the provided 'dayOfYear'
package com.logicbig.example.offsetdatetime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class WithDayOfYearExample { public static void main(String... args) { OffsetDateTime d = OffsetDateTime.of(2016, 12, 15, 18, 29, 32, 3000000, ZoneOffset.ofHours(-5)); System.out.println(d); OffsetDateTime d2 = d.withDayOfYear(20); System.out.println(d2); }}
2016-12-15T18:29:32.003-05:002016-01-20T18:29:32.003-05:00