Java时间工具类(Date和LocalDateTime)

Date

在这里插入图片描述

package com.qiangesoft.utils.date;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;/*** 日期工具类** @author lq* @date 2024-05-23*/
public class DateUtil {public static final String[] CHINESE_WEEK_DAY = new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"};/*** 显示到日期*/public static final String FORMAT_DATE = "yyyy-MM-dd";/*** 显示到小时*/public static final String FORMAT_HOUR = "yyyy-MM-dd HH";/*** 显示到分*/public static final String FORMAT_MINUTE = "yyyy-MM-dd HH:mm";/*** 显示到秒*/public static final String FORMAT_SECOND = "yyyy-MM-dd HH:mm:ss";/*** 显示到毫秒*/public static final String FORMAT_MILLISECOND = "yyyy-MM-dd HH:mm:ss:SSS";/*** 数字格式显示到日期*/public static final String FORMAT_DATE_NUMBER = "yyyyMMdd";/*** 数字格式显示到小时*/public static final String FORMAT_HOUR_NUMBER = "yyyyMMddHH";/*** 数字格式显示到分*/public static final String FORMAT_MINUTE_NUMBER = "yyyyMMddHHmm";/*** 数字格式显示到秒*/public static final String FORMAT_SECOND_NUMBER = "yyyyMMddHHmmss";/*** 数字格式显示到毫秒*/public static final String FORMAT_MILLISECOND_NUMBER = "yyyyMMddHHmmssSSS";/*** 当前时间** @return*/public static Date now() {return new Date();}/*** 当日的开始时间** @return*/public static Date startOfDay() {return startOfDay(now());}/*** 某天的开始时间** @param date* @return*/public static Date startOfDay(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);return calendar.getTime();}/*** 当日的结束时间** @return*/public static Date endOfDay() {return endOfDay(now());}/*** 某天的结束时间** @param date* @return*/public static Date endOfDay(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.HOUR_OF_DAY, 23);calendar.set(Calendar.MINUTE, 59);calendar.set(Calendar.SECOND, 59);calendar.set(Calendar.MILLISECOND, 999);return calendar.getTime();}/*** 本周第几天** @return*/public static int dayOfWeek() {return dayOfWeek(now());}/*** 某周第几天** @param date* @return*/public static int dayOfWeek(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);int dayNum = calendar.get(Calendar.DAY_OF_WEEK);return dayNum == 1 ? 7 : dayNum - 1;}/*** 本周星期几** @return*/public static String dayNameOfWeek() {return dayNameOfWeek(now());}/*** 某周星期几** @param date* @return*/public static String dayNameOfWeek(Date date) {int dayNum = dayOfWeek(date);return CHINESE_WEEK_DAY[dayNum - 1];}/*** 本周的开始时间** @return*/public static Date startOfWeek() {return startOfWeek(now());}/*** 某周的开始时间** @param date* @return*/public static Date startOfWeek(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);return calendar.getTime();}/*** 本周的结束时间** @return*/public static Date endOfWeek() {return endOfWeek(now());}/*** 某周的结束时间** @param date* @return*/public static Date endOfWeek(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);calendar.set(Calendar.HOUR_OF_DAY, 23);calendar.set(Calendar.MINUTE, 59);calendar.set(Calendar.SECOND, 59);calendar.set(Calendar.MILLISECOND, 999);calendar.add(Calendar.WEEK_OF_YEAR, 1);return calendar.getTime();}/*** 当月开始时间** @return*/public static Date startOfMonth() {return startOfMonth(now());}/*** 某月开始时间** @param date* @return*/public static Date startOfMonth(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_MONTH, 1);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);return calendar.getTime();}/*** 当月结束时间** @return*/public static Date endOfMonth() {return endOfMonth(now());}/*** 某月结束时间** @param date* @return*/public static Date endOfMonth(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));calendar.set(Calendar.HOUR_OF_DAY, 23);calendar.set(Calendar.MINUTE, 59);calendar.set(Calendar.SECOND, 59);calendar.set(Calendar.MILLISECOND, 999);return calendar.getTime();}/*** 当年开始时间** @return*/public static Date startOfYear() {return startOfYear(now());}/*** 某年开始时间** @param date* @return*/public static Date startOfYear(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_YEAR, 1);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);return calendar.getTime();}/*** 当年结束时间** @return*/public static Date endOfYear() {return endOfYear(now());}/*** 某年结束时间** @param date* @return*/public static Date endOfYear(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.set(Calendar.DAY_OF_YEAR, calendar.getActualMaximum(Calendar.DAY_OF_YEAR));calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);calendar.set(Calendar.MILLISECOND, 0);return calendar.getTime();}/*** 当日是否属于时间范围内** @param startTime* @param endTime* @return*/public static Boolean between(Date startTime, Date endTime) {return between(now(), startTime, endTime);}/*** 时间范围内** @param date* @param startTime* @param endTime* @return*/public static Boolean between(Date date, Date startTime, Date endTime) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);Calendar start = Calendar.getInstance();start.setTime(startTime);Calendar end = Calendar.getInstance();end.setTime(endTime);return calendar.after(start) && calendar.before(end);}/*** 时间格式化** @param date* @return*/public static String format(Date date) {return format(date, FORMAT_SECOND);}/*** 时间格式化** @param date* @param format* @return*/public static String format(Date date, String format) {SimpleDateFormat dateFormat = new SimpleDateFormat(format);return dateFormat.format(date);}/*** 字符串转时间** @param date* @param format* @return*/public static Date parse(String date, String format) throws ParseException {SimpleDateFormat dateFormat = new SimpleDateFormat(format);return dateFormat.parse(date);}/*** 增加秒** @param second* @return*/public static Date addSecond(int second) {return addSecond(now(), second);}/*** 增加秒** @param date* @param second* @return*/public static Date addSecond(Date date, int second) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.SECOND, second);return calendar.getTime();}/*** 增加分钟** @param minute* @return*/public static Date addMinute(int minute) {return addMinute(now(), minute);}/*** 增加分钟** @param date* @param minute* @return*/public static Date addMinute(Date date, int minute) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.MINUTE, minute);return calendar.getTime();}/*** 增加小时** @param hour* @return*/public static Date addHour(int hour) {return addHour(now(), hour);}/*** 增加小时** @param date* @param hour* @return*/public static Date addHour(Date date, int hour) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.HOUR, hour);return calendar.getTime();}/*** 增加天** @param day* @return*/public static Date addDay(int day) {return addDay(day);}/*** 增加天** @param date* @param day* @return*/public static Date addDay(Date date, int day) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.DATE, day);return calendar.getTime();}/*** 增加周** @param week* @return*/public static Date addWeek(int week) {return addWeek(now(), week);}/*** 增加周** @param date* @param week* @return*/public static Date addWeek(Date date, int week) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.WEEK_OF_YEAR, week);return calendar.getTime();}/*** 增加月** @param month* @return*/public static Date addMonth(int month) {return addMonth(now(), month);}/*** 增加月** @param date* @param month* @return*/public static Date addMonth(Date date, int month) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.MONTH, month);return calendar.getTime();}/*** 增加年** @param year* @return*/public static Date addYear(int year) {return addYear(now(), year);}/*** 增加年** @param date* @param year* @return*/public static Date addYear(Date date, int year) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.YEAR, year);return calendar.getTime();}/*** 减少秒** @param second* @return*/public static Date reduceSecond(int second) {return reduceSecond(now(), second);}/*** 减少秒** @param date* @param second* @return*/public static Date reduceSecond(Date date, int second) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.SECOND, -second);return calendar.getTime();}/*** 减少分钟** @param minute* @return*/public static Date reduceMinute(int minute) {return reduceMinute(now(), minute);}/*** 减少分钟** @param date* @param minute* @return*/public static Date reduceMinute(Date date, int minute) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.MINUTE, -minute);return calendar.getTime();}/*** 减少小时** @param hour* @return*/public static Date reduceHour(int hour) {return reduceHour(now(), hour);}/*** 减少小时** @param date* @param hour* @return*/public static Date reduceHour(Date date, int hour) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.HOUR, -hour);return calendar.getTime();}/*** 减少天** @param day* @return*/public static Date reduceDay(int day) {return reduceDay(now(), day);}/*** 减少天** @param date* @param day* @return*/public static Date reduceDay(Date date, int day) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.DATE, -day);return calendar.getTime();}/*** 减少周** @param week* @return*/public static Date reduceWeek(int week) {return reduceWeek(now(), week);}/*** 减少周** @param date* @param week* @return*/public static Date reduceWeek(Date date, int week) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.WEEK_OF_YEAR, -week);return calendar.getTime();}/*** 减少月** @param month* @return*/public static Date reduceMonth(int month) {return reduceMonth(now(), month);}/*** 减少月** @param date* @param month* @return*/public static Date reduceMonth(Date date, int month) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.MONTH, -month);return calendar.getTime();}/*** 减少年** @param year* @return*/public static Date reduceYear(int year) {return reduceYear(now(), year);}/*** 减少年** @param date* @param year* @return*/public static Date reduceYear(Date date, int year) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.YEAR, -year);return calendar.getTime();}public static void main(String[] args) throws ParseException {Date now = now();System.out.println("现在时间:" + format(now));System.out.println("今天开始时间:" + format(startOfDay(now)));System.out.println("今天结束时间:" + format(endOfDay(now)));System.out.println("本周第几天:" + dayOfWeek(now));System.out.println("本周星期几:" + dayNameOfWeek(now));System.out.println("本周开始时间:" + format(startOfWeek(now)));System.out.println("本周结束时间:" + format(endOfWeek(now)));System.out.println("本月开始时间:" + format(startOfMonth(now)));System.out.println("本月结束时间:" + format(endOfMonth(now)));System.out.println("本年开始时间:" + format(startOfYear(now)));System.out.println("本年结束时间:" + format(endOfYear(now)));System.out.println("是否属于时间范围:" + between(reduceDay(now, 1), addDay(now, 2)));System.out.println("时间格式化:" + format(now, FORMAT_MINUTE));System.out.println("字符串转换时间:" + parse("2024-11-24 11:17:04", FORMAT_SECOND));System.out.println("现在时间加100秒:" + format(addSecond(now, 100)));System.out.println("现在时间加12分钟:" + format(addMinute(now, 12)));System.out.println("现在时间加2小时:" + format(addHour(now, 2)));System.out.println("现在时间加5天:" + format(addDay(now, 5)));System.out.println("现在时间加3周:" + format(addWeek(now, 3)));System.out.println("现在时间加6月:" + format(addMonth(now, 6)));System.out.println("现在时间加1年:" + format(addYear(now, 1)));System.out.println("现在时间减100秒:" + format(reduceSecond(now, 100)));System.out.println("现在时间减12分钟:" + format(reduceMinute(now, 12)));System.out.println("现在时间减2小时:" + format(reduceHour(now, 2)));System.out.println("现在时间减5天:" + format(reduceDay(now, 5)));System.out.println("现在时间减3周:" + format(reduceWeek(now, 3)));System.out.println("现在时间减6月:" + format(reduceMonth(now, 6)));System.out.println("现在时间减1年:" + format(reduceYear(now, 1)));}}

LocalDateTime

在这里插入图片描述

package com.qiangesoft.utils.date;import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;/*** 日期工具类** @author lq* @date 2024-05-23*/
public class LocalDateUtil {public static final String[] CHINESE_WEEK_DAY = new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"};/*** 显示到日期*/public static final String FORMAT_DATE = "yyyy-MM-dd";/*** 显示到小时*/public static final String FORMAT_HOUR = "yyyy-MM-dd HH";/*** 显示到分*/public static final String FORMAT_MINUTE = "yyyy-MM-dd HH:mm";/*** 显示到秒*/public static final String FORMAT_SECOND = "yyyy-MM-dd HH:mm:ss";/*** 显示到毫秒*/public static final String FORMAT_MILLISECOND = "yyyy-MM-dd HH:mm:ss:SSS";/*** 数字格式显示到日期*/public static final String FORMAT_DATE_NUMBER = "yyyyMMdd";/*** 数字格式显示到小时*/public static final String FORMAT_HOUR_NUMBER = "yyyyMMddHH";/*** 数字格式显示到分*/public static final String FORMAT_MINUTE_NUMBER = "yyyyMMddHHmm";/*** 数字格式显示到秒*/public static final String FORMAT_SECOND_NUMBER = "yyyyMMddHHmmss";/*** 数字格式显示到毫秒*/public static final String FORMAT_MILLISECOND_NUMBER = "yyyyMMddHHmmssSSS";/*** 当前时间** @return*/public static LocalDateTime now() {return LocalDateTime.now();}/*** 当日的开始时间** @return*/public static LocalDateTime startOfDay() {return now().toLocalDate().atStartOfDay();}/*** 某天的开始时间** @param date* @return*/public static LocalDateTime startOfDay(LocalDateTime date) {return date.toLocalDate().atStartOfDay();}/*** 当日的结束时间** @return*/public static LocalDateTime endOfDay() {return now().toLocalDate().atTime(LocalTime.MAX);}/*** 某天的结束时间** @param date* @return*/public static LocalDateTime endOfDay(LocalDateTime date) {return date.toLocalDate().atTime(LocalTime.MAX);}/*** 本周第几天** @return*/public static int dayOfWeek() {return dayOfWeek(now());}/*** 某周第几天** @param date* @return*/public static int dayOfWeek(LocalDateTime date) {DayOfWeek dayOfWeek = date.getDayOfWeek();return dayOfWeek.getValue();}/*** 本周星期几** @return*/public static String dayNameOfWeek() {return dayNameOfWeek(now());}/*** 某周星期几** @param date* @return*/public static String dayNameOfWeek(LocalDateTime date) {int dayNum = dayOfWeek(date);return CHINESE_WEEK_DAY[dayNum - 1];}/*** 本周开始时间** @return*/public static LocalDateTime startOfWeek() {return startOfWeek(now());}/*** 某周开始时间** @param date* @return*/public static LocalDateTime startOfWeek(LocalDateTime date) {return date.minusDays(date.getDayOfWeek().getValue() - 1).toLocalDate().atStartOfDay();}/*** 本周结束时间** @return*/public static LocalDateTime endOfWeek() {return endOfWeek(now());}/*** 某周结束时间** @param date* @return*/public static LocalDateTime endOfWeek(LocalDateTime date) {return LocalDateTime.of(LocalDate.from(date.plusDays(8 - date.getDayOfWeek().getValue())), LocalTime.MAX);}/*** 当月开始时间** @return*/public static LocalDateTime startOfMonth() {return startOfMonth(now());}/*** 某月开始时间** @param date* @return*/public static LocalDateTime startOfMonth(LocalDateTime date) {return date.toLocalDate().with(TemporalAdjusters.firstDayOfMonth()).atTime(LocalTime.MIN);}/*** 当月结束时间** @return*/public static LocalDateTime endOfMonth() {return endOfMonth(now());}/*** 某月结束时间** @param date* @return*/public static LocalDateTime endOfMonth(LocalDateTime date) {return date.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()).atTime(LocalTime.MAX);}/*** 当年开始时间** @return*/public static LocalDateTime startOfYear() {return startOfYear(now());}/*** 某年开始时间** @param date* @return*/public static LocalDateTime startOfYear(LocalDateTime date) {return date.toLocalDate().with(TemporalAdjusters.firstDayOfYear()).atTime(LocalTime.MIN);}/*** 当年结束时间** @return*/public static LocalDateTime endOfYear() {return endOfYear(now());}/*** 某年结束时间** @param date* @return*/public static LocalDateTime endOfYear(LocalDateTime date) {return date.toLocalDate().with(TemporalAdjusters.lastDayOfYear()).atTime(LocalTime.MAX);}/*** 当日是否属于时间范围内** @param startTime* @param endTime* @return*/public static Boolean between(LocalDateTime startTime, LocalDateTime endTime) {return between(now(), startTime, endTime);}/*** 时间范围内** @param date* @param startTime* @param endTime* @return*/public static Boolean between(LocalDateTime date, LocalDateTime startTime, LocalDateTime endTime) {return date.isAfter(startTime) && date.isBefore(endTime);}/*** 时间格式化** @param date* @return*/public static String format(LocalDateTime date) {return format(date, FORMAT_SECOND);}/*** 时间格式化** @param date* @param format* @return*/public static String format(LocalDateTime date, String format) {DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);return date.format(formatter);}/*** 字符串转换时间** @param date* @param format* @return*/public static LocalDateTime parse(String date, String format) {DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);return LocalDateTime.parse(date, formatter);}/*** 增加秒** @param second* @return*/public static LocalDateTime addSecond(int second) {return addSecond(now(), second);}/*** 增加秒** @param date* @param second* @return*/public static LocalDateTime addSecond(LocalDateTime date, int second) {return date.plusSeconds(second);}/*** 增加分钟** @param minute* @return*/public static LocalDateTime addMinute(int minute) {return addMinute(now(), minute);}/*** 增加分钟** @param date* @param minute* @return*/public static LocalDateTime addMinute(LocalDateTime date, int minute) {return date.plusMinutes(minute);}/*** 增加小时** @param hour* @return*/public static LocalDateTime addHour(int hour) {return addHour(now(), hour);}/*** 增加小时** @param date* @param hour* @return*/public static LocalDateTime addHour(LocalDateTime date, int hour) {return date.plusHours(hour);}/*** 增加天** @param day* @return*/public static LocalDateTime addDay(int day) {return addDay(now(), day);}/*** 增加天** @param date* @param day* @return*/public static LocalDateTime addDay(LocalDateTime date, int day) {return date.plusDays(day);}/*** 增加周** @param week* @return*/public static LocalDateTime addWeek(int week) {return addWeek(now(), week);}/*** 增加周** @param date* @param week* @return*/public static LocalDateTime addWeek(LocalDateTime date, int week) {return date.plusWeeks(week);}/*** 增加月** @param month* @return*/public static LocalDateTime addMonth(int month) {return addMonth(now(), month);}/*** 增加月** @param date* @param month* @return*/public static LocalDateTime addMonth(LocalDateTime date, int month) {return date.plusMonths(month);}/*** 增加年** @param year* @return*/public static LocalDateTime addYear(int year) {return addYear(now(), year);}/*** 增加年** @param date* @param year* @return*/public static LocalDateTime addYear(LocalDateTime date, int year) {return date.plusYears(year);}/*** 减少秒** @param second* @return*/public static LocalDateTime reduceSecond(int second) {return reduceSecond(now(), second);}/*** 减少秒** @param date* @param second* @return*/public static LocalDateTime reduceSecond(LocalDateTime date, int second) {return date.minusSeconds(second);}/*** 减少分钟** @param minute* @return*/public static LocalDateTime reduceMinute(int minute) {return reduceMinute(now(), minute);}/*** 减少分钟** @param date* @param minute* @return*/public static LocalDateTime reduceMinute(LocalDateTime date, int minute) {return date.minusMinutes(minute);}/*** 减少小时** @param hour* @return*/public static LocalDateTime reduceHour(int hour) {return reduceHour(now(), hour);}/*** 减少小时** @param date* @param hour* @return*/public static LocalDateTime reduceHour(LocalDateTime date, int hour) {return date.minusHours(hour);}/*** 减少天** @param day* @return*/public static LocalDateTime reduceDay(int day) {return reduceDay(now(), day);}/*** 减少天** @param date* @param day* @return*/public static LocalDateTime reduceDay(LocalDateTime date, int day) {return date.minusDays(day);}/*** 减少周** @param week* @return*/public static LocalDateTime reduceWeek(int week) {return reduceWeek(now(), week);}/*** 减少周** @param date* @param week* @return*/public static LocalDateTime reduceWeek(LocalDateTime date, int week) {return date.minusWeeks(week);}/*** 减少月** @param month* @return*/public static LocalDateTime reduceMonth(int month) {return reduceMonth(now(), month);}/*** 减少月** @param date* @param month* @return*/public static LocalDateTime reduceMonth(LocalDateTime date, int month) {return date.minusMonths(month);}/*** 减少年** @param year* @return*/public static LocalDateTime reduceYear(int year) {return reduceYear(now(), year);}/*** 减少年** @param date* @param year* @return*/public static LocalDateTime reduceYear(LocalDateTime date, int year) {return date.minusYears(year);}public static void main(String[] args) {LocalDateTime now = LocalDateTime.now();System.out.println("现在时间:" + format(now));System.out.println("今天开始时间:" + format(startOfDay(now)));System.out.println("今天结束时间:" + format(endOfDay(now)));System.out.println("本周第几天:" + dayOfWeek(now));System.out.println("本周星期几:" + dayNameOfWeek(now));System.out.println("本周开始时间:" + format(startOfWeek(now)));System.out.println("本周结束时间:" + format(endOfWeek(now)));System.out.println("本月开始时间:" + format(startOfMonth(now)));System.out.println("本月结束时间:" + format(endOfMonth(now)));System.out.println("本年开始时间:" + format(startOfYear(now)));System.out.println("本年结束时间:" + format(endOfYear(now)));System.out.println("是否属于时间范围:" + between(reduceDay(now, 1), addDay(now, 2)));System.out.println("时间格式化:" + format(now, FORMAT_MINUTE));System.out.println("字符串转换时间:" + parse("2024-11-24 11:17:04", FORMAT_SECOND));System.out.println("现在时间加100秒:" + format(addSecond(now, 100)));System.out.println("现在时间加12分钟:" + format(addMinute(now, 12)));System.out.println("现在时间加2小时:" + format(addHour(now, 2)));System.out.println("现在时间加5天:" + format(addDay(now, 5)));System.out.println("现在时间加3周:" + format(addWeek(now, 3)));System.out.println("现在时间加6月:" + format(addMonth(now, 6)));System.out.println("现在时间加1年:" + format(addYear(now, 1)));System.out.println("现在时间减100秒:" + format(reduceSecond(now, 100)));System.out.println("现在时间减12分钟:" + format(reduceMinute(now, 12)));System.out.println("现在时间减2小时:" + format(reduceHour(now, 2)));System.out.println("现在时间减5天:" + format(reduceDay(now, 5)));System.out.println("现在时间减3周:" + format(reduceWeek(now, 3)));System.out.println("现在时间减6月:" + format(reduceMonth(now, 6)));System.out.println("现在时间减1年:" + format(reduceYear(now, 1)));}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/839699.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HiWoo Box边缘计算网关

​在数字化浪潮汹涌的今天,边缘计算网关成为了连接物理世界与数字世界的桥梁,其重要性日益凸显。HiWoo Box,作为一款功能强大的边缘计算网关,不仅具备了传统网关的基本功能,更在数据采集、处理、传输等方面展现出了卓越…

automa:循环元素的一个示例,取TME结合插件实现自动下载音乐。

因为tme没提供批量下载音乐的功能。我找到了一个插件可以下载。但需要点击播放时,才能感 知。 我原来用python写了一个,能实现,这想把他移植到automa上,同时想使用循环元素的方法,避免不必要的时间浪费。 开始。首先…

2024年商业管理与文化传播国际学术会议(ICBMCC 2024)

2024年商业管理与文化传播国际学术会议(ICBMCC 2024) 2024 International Conference on Business Management and Cultural Communication 一、【会议简介】 2024年商业管理与文化传播国际学术会议(ICBMCC 2024)是一次汇集全球商业管理领域…

Vaex :突破pandas,快速分析100G大数据量

pandas处理大数据的限制 现在的数据科学比赛提供的数据量越来越大,动不动几十个G,甚至上百G,这就要考验机器性能和数据处理能力。 Python中的pandas是大家常用的数据处理工具,能应付较大数据集(千万行级别&#xff09…

HarmonyOS之ArkUI布局设计常见细节

这里写目录标题 1. Button设置带有渐变色的背景图片无效1.1 问题分析1.2 成功案例 2. 路由跳转失败2.1 问题分析 1. Button设置带有渐变色的背景图片无效 1.1 问题分析 说明:设置颜色渐变需先设置backgroundColor为透明色。 Button($r(app.string.login), { type…

Logrus IT的专家们已将游戏《菇勇者传说》翻译成俄语

《菇勇者传说》是一款引人入胜的放置类RPG游戏,邪恶的龙将所有人变成了蘑菇。为了恢复人类形态,玩家的角色需要从小蘑菇成长为强大的勇士。 游戏中有多个蘑菇职业,每个职业都有独特的技能。玩家可以根据自己的喜好提升角色的属性和改变外观&…

0基础从前端到Web3 —— Mine Clearance Frontend(一)

初始化项目以及通过dapp-kit连接钱包的部分就不再赘述&#xff0c;具体可以点击查看&#xff0c;如果篇幅当中遇到了一些未添加的依赖项&#xff0c;直接通过pnpm add -D <name>一般都可以解决。 一&#xff1a;链上网络切换 这里提供一个最简单的切换方式&#xff0c;…

Obsidian Git 多端同步

2023年6月&#xff0c;某云笔记限制了免费用户最多同时登录 2 台设备&#xff0c;想要增加设备数量需要付费开通会员。之后我一直想找一款合适的笔记本软件&#xff0c;年底尝试了Obsidian&#xff0c;断断续续摸索了好几天终于成功了。将那时的笔记拿来分享一下。 相关地址&am…

FPGA搭积木之按键消抖(改进版)

目录 1.前言 2.回顾之前的设计 3.基于读者思路的设计 4.ModelSim仿真 1.前言 昨天分享的关于FPGA对机械按键消抖的设计&#xff0c;有读者指出了其中的不足&#xff0c;并给出了他的思路。今天就读者的设计思路&#xff0c;来再做一个按键消抖模块。这个程序大概是大学的时…

亚马逊、eBay、沃尔玛、OZON、速卖通等平台自养号攻略,助力测评补单

当前&#xff0c;跨境电商面临着巨大的挑战&#xff0c;其运营环境日益变得错综复杂。然而&#xff0c;这种复杂性可以归结为两个核心元素&#xff1a;买与刷。商家们通过进行买卖交易或补单操作&#xff0c;旨在增加销售、提升产品排名&#xff0c;并进而增强产品的权重。 销…

docker-如何将容器外的脚本放入容器内,将容器内的脚本放入容器外

文章目录 前言docker-如何将容器外的脚本放入容器内&#xff0c;将容器内的脚本放入容器外、1. docker 如何将容器外的脚本放入容器内1.1. 验证 2. 将容器内的脚本放入容器外 前言 如果您觉得有用的话&#xff0c;记得给博主点个赞&#xff0c;评论&#xff0c;收藏一键三连啊&…

VMware Workstation 虚拟机安装 ubuntu 24.04 server 详细教程 服务器安装图形化界面

1 阿里云下载 ubuntu-releases安装包下载_开源镜像站-阿里云 2 打开vmware,新建虚拟机 3 选择下载的镜像,开始安装 3 光驱这里修改下 4 重新启动&#xff0c;安装图形化界面 #更新软件包列表 sudo apt-get update #安装Ubuntu图形桌面 sudo apt install ubuntu-desktop 5 安…

【调试笔记-20240524-Linux-扩展 OpenWrt-23.05 发行版 EXT4 镜像文件大小】

调试笔记-系列文章目录 调试笔记-20240524-Linux-扩展 OpenWrt-23.05 发行版 EXT4 镜像文件大小 文章目录 调试笔记-系列文章目录调试笔记-20240524-Linux-扩展 OpenWrt-23.05 发行版 EXT4 镜像文件大小 前言一、调试环境操作系统&#xff1a;Ubuntu 22.04.4 LTS工作环境调试目…

【SD-WAN】香港企业进入粤港澳大湾区所面临的机遇和挑战

粤港澳大湾区发展及规划是中国其中一个主点发展战略&#xff0c;具备完整的多元化产业结构&#xff0c;城市之间建立强大的经济互补性&#xff0c;是国际性湾区和世界级城市群。因此&#xff0c;大湾区近年吸引了不少香港的创新及科技企业前往发展投资及设立据点扩展业务。本文…

增强版 Kimi:AI 驱动的智能创作平台,实现一站式内容生成(图片、PPT、PDF)!

前言 基于扣子 Coze 零代码平台&#xff0c;我们从零到一轻松实现了专属 Bot 机器人的搭建。 AI 大模型&#xff08;LLM&#xff09;、智能体&#xff08;Agent&#xff09;、知识库、向量数据库、知识图谱&#xff0c;RAG&#xff0c;AGI 的不同形态愈发显现&#xff0c;如何…

SpringBoot中注解@RestController | @ResponseBody | @Controller

ResponseBody 可以修饰类和方法 Controller 和 RestController 只能修饰类 RestController 告诉Spring&#xff0c;帮我们管理这个代码&#xff0c;我们后续访问时&#xff0c;才能访问到 RequestMapping 路由映射&#xff0c;可以修饰方法&#xff0c;也可以修饰类 访问地址…

【Linux网络编程】IO多种转接之Reactor

Reactor 点赞&#x1f44d;&#x1f44d;收藏&#x1f31f;&#x1f31f;关注&#x1f496;&#x1f496; 你的支持是对我最大的鼓励&#xff0c;我们一起努力吧!&#x1f603;&#x1f603; 基于上一篇epoll的学习&#xff0c;现在我们也知道epoll的工作模式有两种&#xff0c…

【UE5.1 多线程 异步】“Async Blueprints Extension”插件使用记录

目录 一、异步生成Actor示例 二、异步计算示例 参考视频 首先需要在商城中下载“Async Blueprints Extension”插件 一、异步生成Actor示例 2. 创建一个线程类&#xff0c;这里要指定父类为“LongAsyncTask”、“InfiniteAsyncTask”、“ShortAsyncTask”中的一个 在线程类…

el-table 实现嵌套表格的思路及完整功能代码

要实现的需求是这样的&#xff1a; 本来我是用 el-table 的 :span-method 方法实现的&#xff0c;但发现合并起来有问题&#xff0c;跟我的需求差距有些大&#xff0c;于是我想到了嵌套表格。但是嵌套完之后的样子也是很奇怪&#xff1a; 不要气馁&#xff0c;思路还是对的&a…

基于文心智能体平台打造专属情感类陪伴智能体【情绪价值提供者】

文章目录 一、文心智能体平台介绍二、文心智能体平台注册三、智能体介绍四、智能体创建过程4.1 基础配置4.2 高级配置4.3 预览调优4.4 公开发布 五、智能体使用心得六、智能体分享方式七、参考链接 一、文心智能体平台介绍 文心智能体平台是百度推出的基于文心大模型的智能体&…