datetime - Adding java time objects -


How do you say, can you add 1 hour to the given result from the calendar gettime?

tl; Dr

  Instant. Now (). PlusHours (1)  

... or ...

ZonedDateTime.now (Jonid. ("America / Montreal") .plusHours (1)

Time to use Java

The accepted answer is correct but is out of date.

The problem is to go to the old heritage date-time classes. Time classes have been provided.

Instead, use Calendar , ZonedDateTime .

  ZoneId Z = ZoneId.of ("America / Montreal"); ZonedDateTime zdt = ZonedDateTime.now (Z); ZonedDateTime zdtOneHourLater = zdt.plusHours (1);  

Do not let that one hour later may not happen, as if one hour later, it may be that two hours later from 1 a.m. to DST switch-over

Endar to see the modern Java time types.

Most of your work should be in UTC. For this, use instant class.

  Instant Battery = Instant.Now (). PlusHours (1);  

About java.time

The framework is built in Java 8 and later. These classes trouble the old date-time classes such as java.util.Date , . Calendar , & amp; java.text.SimpleDateFormat .

Now the project advises migration in Java time.

To learn more, find more stack overflow for more examples and explanations.

Mostly Java Time Performance Java 6 & amp; Customized in (and more) in 7 further.

The java.time has been extended with additional classes in this project. This project is probably the proven ground for java.time for future additions. You can find some useful categories here such as interval , anniversary, , year-quarter quarters and more.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -