In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the example usage of JAVA Date time tool class". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the example usage of the JAVA Date time tool class.
Import java.text.ParseException;import java.time.*;import java.time.format.DateTimeFormatter;import java.time.temporal.TemporalAdjusters;import java.util.Date;/** * @ description: time tool class * @ author: kejie.huang * @ date: Created in 2019-10-10 11:08 * @ version: * @ modified By: * / public class DateUtils {public static final String DATE_FORMART_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss" / * * date after the specified date plus days * @ param num is the increased number of days * @ param currentDate creation time * @ return * @ throws ParseException * / public static Date plusDay (int num, Date currentDate) {LocalDateTime localDateTime = dateConvertLocalDateTime (currentDate); localDateTime = localDateTime.plusDays (num); return localDateTimeConvertDate (localDateTime) } / * * @ description converts into * @ return * @ author kejie.huang * @ date 11:19 * / public static Date dateStrConvertDate (String currentDate, String formateStr) {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern (formateStr); LocalDateTime localDateTime = LocalDateTime.parse (currentDate, dateTimeFormatter); return localDateTimeConvertDate (localDateTime) according to the time string } / * * @ return * @ description is converted to localDateTime * @ author kejie.huang * @ date according to date 14:31 * / private static LocalDateTime dateConvertLocalDateTime (Date date) {LocalDateTime localDateTime = Instant.ofEpochMilli (date.getTime ()) .atZone (ZoneId.systemDefault ()) .toLocalDateTime (); return localDateTime } / * * @ return * @ description method description converted to date * @ author kejie.huang * @ date according to localDateTime 14:31 * / public static Date localDateTimeConvertDate (LocalDateTime localDateTime) {return Date.from (getZonedDateTimeByLocalDateTime (localDateTime). ToInstant ()) } / * @ description converts the time string * @ return * @ author kejie.huang * @ date according to time 11:19 * / public static String formatDateToParse (Date currentDate, String formateStr) {LocalDateTime localDateTime = dateConvertLocalDateTime (currentDate); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern (formateStr); return dateTimeFormatter.format (localDateTime) } / * * @ description compare according to start time and end time * @ param startDate start time * @ param endDate end time * @ return * @ author kejie.huang * @ date, 2019-10-10 11:16 * / public static boolean compareDay (Date startDate, Date endDate) {return startDate.before (endDate) } / * * @ title DateUtils * @ Description get the first day of this month * @ author kejie.huang * @ Date on 2019-10-14 10:52 * @ Copyright 2019-2020 * / public static Date getMonthFirstDay () {LocalDateTime date = LocalDateTime.now (); LocalDateTime firstday = date.with (TemporalAdjusters.firstDayOfMonth ()); return localDateTimeConvertDate (firstday) } / * * @ title DateUtils * @ Description get the last day of this month * @ author kejie.huang * @ Date on 2019-10-14 10:52 * @ Copyright 2019-2020 * / public static Date getMonthLastDay () {LocalDateTime date = LocalDateTime.now (); LocalDateTime lastday = date.with (TemporalAdjusters.lastDayOfMonth ()); return localDateTimeConvertDate (lastday) } / * * @ title DateUtils * @ Description converts localDatTime to ZonedDateTime object according to localDateTime, which is used to convert localDatTime to Date * @ author kejie.huang * @ Date 11:03 on 2019-10-14 * @ Copyright 2019-2020 * / public static ZonedDateTime getZonedDateTimeByLocalDateTime (LocalDateTime localDateTime) {ZoneId zoneId = ZoneId.systemDefault (); ZonedDateTime zonedDateTime = localDateTime.atZone (zoneId); return zonedDateTime } / * * @ return * @ description get the maximum time of a day 2019-10-14 23:59:59 * @ author kejie.huang * @ date 2019-10-14 10:56 * / public static Date getEndOfDay (Date date) {LocalDateTime localDateTime = LocalDateTime.ofInstant (Instant.ofEpochMilli (date.getTime ()), ZoneId.systemDefault ()); LocalDateTime endOfDay = localDateTime.with (LocalTime.MAX) Return localDateTimeConvertDate (endOfDay);} / * * @ return * @ description get the minimum time of a certain day 2019-10-14 00:00:00 * @ author kejie.huang * @ date 10:57 * / public static Date getStartOfDay (Date date) {LocalDateTime localDateTime = LocalDateTime.ofInstant (Instant.ofEpochMilli (date.getTime ()), ZoneId.systemDefault ()) LocalDateTime startOfDay = localDateTime.with (LocalTime.MIN); return localDateTimeConvertDate (startOfDay);}} at this point, I believe you have a deeper understanding of "the instance usage of the JAVA Date time tool class". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.