Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





Java - Code Samples

 Sample 1. Code Sample / Example / Snippet of java.time.temporal.ChronoUnit

    public LocalDateTime plus(long amountToAdd, TemporalUnit unit) {

if (unit instanceof ChronoUnit) {

ChronoUnit f = (ChronoUnit) unit;

switch (f) {

case NANOS: return plusNanos(amountToAdd);

case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);

case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000);

case SECONDS: return plusSeconds(amountToAdd);

case MINUTES: return plusMinutes(amountToAdd);

case HOURS: return plusHours(amountToAdd);

case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is multiple of 2)

}

return with(date.plus(amountToAdd, unit), time);

}

return unit.addTo(this, amountToAdd);

}




   Like      Feedback      java.time.temporal.ChronoUnit



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner