Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the API of java time and date

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly talks about "what are the API of java time and date". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the API of java time and date"?

1. Clock provides the ability to access the current time and date. Clock is sensitive to the current time zone and can be used instead of System.currenttimeMillis () to get the current millisecond time.

Clock clock = Clock.systemDefaultZone (); long millis = clock.millis (); Instant instant = clock.instant (); Date legacyDate = Date.from (instant); / / legacy java.util.Date

2. The local time class represents a time that does not have a specified time zone.

LocalTime now1 = LocalTime.now (zone1); LocalTime now2 = LocalTime.now (zone2); System.out.println (now1.isBefore (now2)); / / false long hoursBetween = ChronoUnit.HOURS.between (now1, now2); long minutesBetween = ChronoUnit.MINUTES.between (now1, now2); System.out.println (hoursBetween); / /-3System.out.println (minutesBetween); / /-239

3. Time zone classes can be represented by ZoneId. Objects of the time zone class can be easily obtained through the static factory method.

System.out.println (ZoneId.getAvailableZoneIds ()); / / prints all available timezone ids ZoneId zone1 = ZoneId.of ("Europe/Berlin"); ZoneId zone2 = ZoneId.of ("Brazil/East"); System.out.println (zone1.getRules ()); System.out.println (zone2.getRules ()); / / ZoneRules [currentStandardOffset=+01:00] / / ZoneRules [currentStandardOffset =-03:00] so far, I believe you have a deeper understanding of "java time and date API", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report