当前位置: 首页 > news >正文

主流建站开源程序有哪些网站优化网站建站教程

主流建站开源程序有哪些,网站优化网站建站教程,wordpress企业宣传电商,罗田建设局网站Java Date LocalDate LocalDateTime Java中常用时间类型 Date LocalDate LocalDateTime 在工作中使用很频繁#xff0c; 但中间很多常用功能每次编写代码很繁琐#xff0c;故而封装了以下三个工具类#xff1a; DateUtil 日期工具类LocalDateUtil 新日期工具类LocalDateTime…Java Date LocalDate LocalDateTime Java中常用时间类型 Date LocalDate LocalDateTime 在工作中使用很频繁 但中间很多常用功能每次编写代码很繁琐故而封装了以下三个工具类 DateUtil 日期工具类LocalDateUtil 新日期工具类LocalDateTimeUtil 新日期工具类 用于日常使用。 Date 工具类 package cn.lihaozhe.util.date;import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.temporal.TemporalAdjusters; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors;/*** 日期工具类** author 李昊哲* version 1.0*/ public class DateUtil {/*** 默认时区*/private final static String timeZone Asia/Shanghai;/*** 默认时区为东 8 区*/private final static ZoneOffset zoneOffset ZoneOffset.of(8);/*** 默认时间字符串模板*/private final static String pattern yyyy-MM-dd HH:mm:ss;/*** 获取当前系统日期** return 当前系统日期*/public static Date date() {return new Date();}/*** 获取当前系统日期日期字符串** return 当前系统日期字符串*/public static String now() {return format(new Date());}/*** 获取当前系统日期日期字符串** param pattern 日期格式化字符串模板* return 当前系统日期字符串*/public static String now(String pattern) {return format(new Date(), pattern);}/*** 日期对象格式化为字符串** param date Date对象* return Date对象格式化后的日期字符串*/public static String format(Date date) {return format(date, pattern);}/*** 日期对象格式化为字符串** param date Date对象* param pattern 日期格式化字符串模板* return Date对象格式化后的日期字符串*/public static String format(Date date, String pattern) {if (date null) {return null;}SimpleDateFormat dateFormat new SimpleDateFormat(pattern);return dateFormat.format(date);}/*** 日期对象格式化为字符串** param date Date对象* param pattern 日期格式化字符串模板* param timeZone 时区* return Date对象格式化后的日期字符串*/public static String format(Date date, String pattern, String timeZone) {SimpleDateFormat dateFormat new SimpleDateFormat(pattern);dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));return dateFormat.format(date);}/*** 获取根据时间毫秒数获取日期** param time 时间毫秒数* return 日期*/public static Date parse(long time) {return new Date(time);}/*** 将日期字符串解析为日期对象** param src 日期字符串* return 日期字符串解析后日期对象* throws ParseException 日期解析异常*/public static Date parse(String src) throws ParseException {return parse(src, pattern);}/*** 将日期字符串解析为日期对象** param src 日期字符串* param pattern 日期格式化字符串模板* return 日期字符串解析后日期对象* throws ParseException 日期解析异常*/public static Date parse(String src, String pattern) throws ParseException {return new SimpleDateFormat(pattern).parse(src);}/*** 将日期字符串解析为日期对象** param src 日期字符串* param pattern 日期格式化字符串模板* param timeZone 时区* return 日期字符串解析后日期对象* throws ParseException 日期解析异常*/public static Date parse(String src, String pattern, String timeZone) throws ParseException {SimpleDateFormat dateFormat new SimpleDateFormat(pattern);dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));return dateFormat.parse(src);}/*** 获取系统当前日期时间毫秒数** return 当前时间毫秒数*/public static long getTime() {return getTime(new Date());}/*** 获取日期时间毫秒数** param date 日期* return 时间毫秒数*/public static long getTime(Date date) {return date.getTime();}/*** 时间补零占位** param time 时间* return 补零后的字符串*/public static String zeroCompensation(int time) {if (time 10) {return 0 time;}return String.valueOf(time);}/*** 生成范围的随机时间位于[start,end)范围内 时间倒序排列** param start 开始时间格式字符串* param end 结束时间格式字符串* param count 生成时间数量* return 随机时间的集合*/public static ListDate random(String start, String end, int count) throws ParseException {return random(parse(start), parse(end), count);}/*** 生成范围的随机时间位于[start,end)范围内 时间倒序排列** param start 开始时间* param end 结束时间* param count 生成时间数量* return 随机时间的集合*/public static ListDate random(Date start, Date end, int count) {return ThreadLocalRandom.current().longs(count, start.getTime(), end.getTime()).mapToObj(Date::new).sorted(Date::compareTo).collect(Collectors.toList());}/*** 生成范围的随机时间位于[start,end)范围内 时间倒序排列** param start 开始时间* param end 结束时间* param count 生成时间数量* return 随机时间的集合*/public static ListLocalDate random(LocalDate start, LocalDate end, int count) {ListDate dateList ThreadLocalRandom.current().longs(count, LocalDateUtils.getMilliSeconds(start), LocalDateUtils.getMilliSeconds(end)).mapToObj(Date::new).sorted(Date::compareTo).toList();return dateList.stream().map(DateUtils::toLocalDate).collect(Collectors.toList());}/*** 生成范围的随机时间位于[start,end)范围内 时间倒序排列** param start 开始时间* param end 结束时间* param count 生成时间数量* return 随机时间的集合*/public static ListLocalDateTime random(LocalDateTime start, LocalDateTime end, int count) {ListDate dateList ThreadLocalRandom.current().longs(count, LocalDateTimeUtils.getTime(start), LocalDateTimeUtils.getTime(end)).mapToObj(Date::new).sorted(Date::compareTo).toList();return dateList.stream().map(DateUtils::toLocalDateTime).collect(Collectors.toList());}/*** LocalDate 转 Date** param localDate LocalDate对象* return Date对象*/private static Date from(LocalDate localDate) {return from(localDate, zoneOffset);}/*** LocalDate 转 Date** param localDate LocalDate对象* param zoneId zoneId* return Date对象*/private static Date from(LocalDate localDate, String zoneId) {return from(localDate, ZoneOffset.of(zoneId));}/*** LocalDate 转 Date** param localDate LocalDate对象* param zoneOffset 时区* return Date对象*/private static Date from(LocalDate localDate, ZoneOffset zoneOffset) {return Date.from(localDate.atStartOfDay(zoneOffset).toInstant());}/*** LocalDateTime 转 Date** param localDateTime LocalDateTime对象* return Date对象*/private static Date from(LocalDateTime localDateTime) {return from(localDateTime, zoneOffset);}/*** LocalDateTime 转 Date** param localDateTime LocalDateTime* param zoneId zoneId* return Date对象*/private static Date from(LocalDateTime localDateTime, String zoneId) {return from(localDateTime, ZoneOffset.of(zoneId));}/*** LocalDateTime 转 Date** param localDateTime LocalDateTime对象* param zoneOffset 时区* return Date对象*/private static Date from(LocalDateTime localDateTime, ZoneOffset zoneOffset) {return Date.from(localDateTime.toInstant(zoneOffset));}/*** Date 转 LocalDate** param date Date对象* return LocalDateTime对象*/public static LocalDate toLocalDate(Date date) {return toLocalDate(date, zoneOffset);}/*** Date 转 LocalDate** param date Date对象* param zoneId 时区ID* return LocalDateTime对象*/public static LocalDate toLocalDate(Date date, String zoneId) {return toLocalDate(date, ZoneOffset.of(zoneId));}/*** Date 转 LocalDate** param date Date对象* param zoneOffset 时区* return LocalDate对象*/public static LocalDate toLocalDate(Date date, ZoneOffset zoneOffset) {return date.toInstant().atOffset(zoneOffset).toLocalDate();}/*** Date 转 LocalDate** param date Date对象* return Date对象*/public static LocalDateTime toLocalDateTime(Date date) {return toLocalDateTime(date, zoneOffset);}/*** Date 转 LocalDate** param date Date对象* param zoneId 时区ID* return LocalDateTime对象*/public static LocalDateTime toLocalDateTime(Date date, String zoneId) {return toLocalDateTime(date, ZoneOffset.of(zoneId));}/*** Date 转 LocalDateTime** param date Date对象* param zoneOffset 时区* return LocalDateTime对象*/public static LocalDateTime toLocalDateTime(Date date, ZoneOffset zoneOffset) {return date.toInstant().atOffset(zoneOffset).toLocalDateTime();}/*** 获取某日期所在年份的第一天的日期** param date 日期* return 所在年份的第一天的日期* throws ParseException ParseException*/public static Date firstDateOfYear(Date date) throws ParseException {return parse(format(date, yyyy), yyyy);}/*** 获取某日期所在年份的最后一天的日期** param date 日期* return 所在年份的最后一天的日期* throws ParseException ParseException*/public static Date lastDateOfYear(Date date) throws ParseException {return parse(format(date, yyyy) -12-31 23:59:59, pattern);}/*** 获取某日期所在月份的第一天的日期** param date 日期* return 所在月份的第一天的日期* throws ParseException ParseException*/public static Date firstDateOfMonth(Date date) throws ParseException {return parse(format(date, yyyy-MM) -01, yyyy-MM-dd);}/*** 获取某日期所在月份的最后一天的日期** param date 日期* return 所在月份的最后一天的日期* throws ParseException ParseException*/public static Date lastDateOfMonth(Date date) throws ParseException {return from(toLocalDateTime(date).with(TemporalAdjusters.lastDayOfMonth()));} } LocalDate 工具类 package cn.lihaozhe.util.date;import java.time.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.ThreadLocalRandom;/*** LocalDate 工具类** author 李昊哲* version 1.0*/ public class LocalDateUtil {/*** 日期格式化模板字符串*/private static final String formatter yyyy-MM-dd;/*** 默认时区为东 8 区*/private final static ZoneOffset zoneOffset ZoneOffset.of(8);/*** 将LocalDate格式化为默认的日期格式字符串 例如1983-11-22** param localDate 欲被格式化的日期* return 根据日期格式字符串模板格式化的时间字符串*/public static String format(LocalDate localDate) {return format(localDate, formatter);}/*** 将LocalDate格式化为指定的日期格式字符串** param localDate 欲被格式化的日期* param formatter 日期字符串模板* return 根据日期格式字符串模板格式化的时间字符串*/public static String format(LocalDate localDate, String formatter) {if (localDate null) {return null;}return DateTimeFormatter.ofPattern(formatter).format(localDate);// return localDate.format(DateTimeFormatter.ofPattern(formatter));}/*** 根据默认日期字符串模板将日期格式字符串解析为LocalDate* 默认日期字符串模板 yyyy-MM-dd** param text 日期格式字符串* return LocalDate*/public static LocalDate parse(String text) {return parse(text, formatter);}/*** 根据日期字符串模板将日期格式字符串解析为LocalDate** param text 日期格式字符串* param formatter 日期格式字符串模板* return LocalDate*/public static LocalDate parse(String text, String formatter) {return LocalDate.parse(text, DateTimeFormatter.ofPattern(formatter));}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* return LocalDate*/public static LocalDate from(Date date) {return from(date, zoneOffset);}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zoneId 时区ID* return LocalDate*/public static LocalDate from(Date date, String zoneId) {return from(date, ZoneOffset.of(zoneId));}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zone 时区* return LocalDate*/public static LocalDate from(Date date, ZoneId zone) {return date.toInstant().atZone(zone).toLocalDate();}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zoneOffset 时区* return LocalDate*/public static LocalDate from(Date date, ZoneOffset zoneOffset) {return date.toInstant().atOffset(zoneOffset).toLocalDate();}/*** LocalDate 转 Date** param localDate LocalDate对象* return Date对象*/public static Date toDate(LocalDate localDate) {return toDate(localDate, zoneOffset);}/*** LocalDate 转 Date** param localDate LocalDate对象* param zoneId zoneId* return Date对象*/public static Date toDate(LocalDate localDate, String zoneId) {return toDate(localDate, ZoneOffset.of(zoneId));}/*** LocalDate 转 Date** param localDate LocalDate对象* param zoneOffset 时区* return Date对象*/public static Date toDate(LocalDate localDate, ZoneOffset zoneOffset) {return Date.from(localDate.atStartOfDay(zoneOffset).toInstant());}/*** LocalDateTime 转 LocalDateTime** param localDate LocalDate对象* return LocalDateTime对象*/public static LocalDateTime toLocalDateTime(LocalDate localDate) {return toLocalDateTime(localDate, zoneOffset);}/*** LocalDateTime 转 LocalDateTime** param localDate LocalDate对象* param zoneId 时区ID* return LocalDateTime对象*/public static LocalDateTime toLocalDateTime(LocalDate localDate, String zoneId) {return toLocalDateTime(localDate, ZoneOffset.of(zoneId));}/*** LocalDateTime 转 LocalDateTime** param localDate LocalDate对象* param zoneOffset 时区* return LocalDateTime对象*/public static LocalDateTime toLocalDateTime(LocalDate localDate, ZoneOffset zoneOffset) {return localDate.atStartOfDay(zoneOffset).toLocalDateTime();}/*** 获取时间毫秒数** return 时间毫秒数*/public static long getMilliSeconds() {return getMilliSeconds(LocalDate.now());}/*** 获取时间毫秒数** param localDate LocalDate对象* return 时间毫秒数*/public static long getMilliSeconds(LocalDate localDate) {return getMilliSeconds(localDate, zoneOffset);}/*** 获取时间毫秒数** param localDate LocalDate对象* param zoneId 时区ID* return 时间毫秒数*/public static long getMilliSeconds(LocalDate localDate, String zoneId) {return getMilliSeconds(localDate, ZoneOffset.of(zoneId));}/*** 获取时间毫秒数** param localDate LocalDate对象* param zoneOffset 时区* return 时间毫秒数*/public static long getMilliSeconds(LocalDate localDate, ZoneOffset zoneOffset) {return toLocalDateTime(localDate, zoneOffset).toInstant(zoneOffset).toEpochMilli();}/*** 时间毫秒数转LocalDate 使用系统默认时区** param milliSeconds 时间毫秒数* return LocalDate*/public static LocalDate parseMilliSeconds(Long milliSeconds) {return parseMilliSeconds(milliSeconds, ZoneId.systemDefault());}/*** 时间毫秒数转LocalDate** param milliSeconds 时间毫秒数* param zoneId 时区* return LocalDate*/public static LocalDate parseMilliSeconds(Long milliSeconds, ZoneId zoneId) {return Instant.ofEpochMilli(milliSeconds).atZone(zoneId).toLocalDate();}/*** 随机生成 LocalDate 集合** param start 开始日期字符串 日期字符串格式 yyyy-MM-dd* param end 结束日期字符串 日期字符串格式 yyyy-MM-dd* param count 随机数量* return LocalDate LocalDate集合*/public static ListLocalDate random(String start, String end, int count) {return random(start, end, count, formatter);}/*** 随机生成 LocalDate 集合** param start 开始日期字符串* param end 结束日期字符串* param count 随机数量* param formatter 日期字符串模板* return LocalDate LocalDate集合*/public static ListLocalDate random(String start, String end, int count, String formatter) {return random(parse(start, formatter), parse(end, formatter), count);}/*** 随机生成 LocalDate 集合** param start 开始日期* param end 结束日期* param count 随机数量* return LocalDate LocalDate集合*/public static ListLocalDate random(LocalDate start, LocalDate end, int count) {ListLocalDate list new ArrayList();for (int i 0; i count; i) {list.add(parseMilliSeconds(ThreadLocalRandom.current().nextLong(getMilliSeconds(start), getMilliSeconds(end))));}if (!list.isEmpty()) {list.sort(LocalDate::compareTo);}return list;} } LocalDateTime 工具类 package cn.lihaozhe.util.date;import java.time.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.ThreadLocalRandom;/*** LocalDateTime 工具类** author 李昊哲* version 1.0* create 2023-10-18*/ public class LocalDateTimeUtil {/*** 时间格式化模板字符串*/private static final String formatter yyyy-MM-dd HH:mm:ss;/*** 默认时区为东 8 区*/private static final ZoneOffset zoneOffset ZoneOffset.of(8);/*** 将LocalDateTime格式化为时间指定的时间格式字符串** param localDateTime 欲被格式化的时间* return 根据时间格式字符串模板格式化的时间字符串*/public static String format(LocalDateTime localDateTime) {return format(localDateTime, formatter);}/*** 将LocalDateTime格式化为时间指定的时间格式字符串** param localDateTime 欲被格式化的时间* param formatter 时间字符串模板* return 根据时间格式字符串模板格式化的时间字符串*/public static String format(LocalDateTime localDateTime, String formatter) {if (localDateTime null) {return null;}return DateTimeFormatter.ofPattern(formatter).format(localDateTime);// return localDateTime.format(DateTimeFormatter.ofPattern(formatter));}/*** 根据时间字符串模板将时间格式字符串解析为LocalDateTime** param text 时间字符串* return LocalDateTime*/public static LocalDateTime parse(String text) {return parse(text, formatter);}/*** 根据时间字符串模板将时间格式字符串解析为LocalDateTime** param text 时间字符串* param formatter 时间字符串模板* return LocalDateTime*/public static LocalDateTime parse(String text, String formatter) {return LocalDateTime.parse(text, DateTimeFormatter.ofPattern(formatter));}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* return LocalDate*/public static LocalDateTime from(Date date) {return from(date, zoneOffset);}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zoneId 时区ID* return LocalDate*/public static LocalDateTime from(Date date, String zoneId) {return from(date, ZoneOffset.of(zoneId));}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zone 时区* return LocalDate*/public static LocalDateTime from(Date date, ZoneId zone) {return date.toInstant().atZone(zone).toLocalDateTime();}/*** Date类型的时间转为LocalDateTime类型的时间** param date Date* param zoneOffset 时区* return LocalDateTime*/public static LocalDateTime from(Date date, ZoneOffset zoneOffset) {return date.toInstant().atOffset(zoneOffset).toLocalDateTime();}/*** LocalDate 转 Date** param localDateTime LocalDateTime对象* return Date对象*/public static Date toDate(LocalDateTime localDateTime) {return toDate(localDateTime, zoneOffset);}/*** LocalDate 转 Date** param localDateTime LocalDateTime对象* param zoneId zoneId* return Date对象*/public static Date toDate(LocalDateTime localDateTime, String zoneId) {return toDate(localDateTime, ZoneOffset.of(zoneId));}/*** LocalDate 转 Date** param localDateTime LocalDateTime对象* param zoneOffset 时区* return Date对象*/public static Date toDate(LocalDateTime localDateTime, ZoneOffset zoneOffset) {return Date.from(localDateTime.toInstant(zoneOffset));}/*** 获取当前时间毫秒数** return 当前时间毫秒数*/public static long getTime() {return LocalDateTime.now(ZoneOffset.of(8)).toInstant(ZoneOffset.of(8)).toEpochMilli();}/*** 获取时间毫秒数** param localDateTime 日期时间* return 当前时间毫秒数*/public static long getTime(LocalDateTime localDateTime) {return localDateTime.toInstant(ZoneOffset.of(8)).toEpochMilli();}/*** 时间毫秒数转LocalDateTime** param milliseconds 时间毫秒数* return LocalDateTime*/public static LocalDateTime parseMilliSeconds(Long milliseconds) {return LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), ZoneId.systemDefault());}/*** 时间毫秒数转LocalDateTime** param milliseconds 时间毫秒数* param zoneId ZoneId* return LocalDateTime*/public static LocalDateTime parseMilliSeconds(Long milliseconds, ZoneId zoneId) {return LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), zoneId);}/*** 随机生成 LocalDate 集合** param start 开始时间字符串 时间字符串格式 yyyy-MM-dd HH:mm:ss* param end 结束时间字符串 时间字符串格式 yyyy-MM-dd HH:mm:ss* param count 随机数量* return LocalDateTime 集合*/public static ListLocalDateTime random(String start, String end, int count) {return random(start, end, count, formatter);}/*** 随机生成 LocalDateTime 集合** param start 开始时间字符串* param end 结束时间字符串* param count 随机数量* param formatter 时间字符串模板* return LocalDateTime LocalDateTime集合*/public static ListLocalDateTime random(String start, String end, int count, String formatter) {return random(parse(start, formatter), parse(end, formatter), count);}/*** 随机生成 LocalDateTime 集合** param start 开始时间* param end 结束时间* param count 随机数量* return LocalDateTime 集合*/public static ListLocalDateTime random(LocalDateTime start, LocalDateTime end, int count) {ListLocalDateTime list new ArrayList();for (int i 0; i count; i) {list.add(parseMilliSeconds(ThreadLocalRandom.current().nextLong(getTime(start), getTime(end))));}if (!list.isEmpty()) {list.sort(LocalDateTime::compareTo);}return list;} }
http://www.zqtcl.cn/news/51007/

相关文章:

  • 网站上的ar是什么软件做的微云怎么做网站
  • 第9类商标有网站开发专业网站定制 北京
  • wordpress下载后放哪三明seo培训
  • 深圳全网建站公司推荐wordpress迁移后后台登陆不
  • 甘肃住房城乡建设厅网站首页微电影网站源码
  • 外管局网站先支后收怎么做报告策划书网站
  • 电脑做兼职找那个网站为什么自己做的网站老是404错误
  • 广州从化网站建设南海最新军事新闻
  • 网站设计素材模板中铁建设集团集采网站
  • 安顺建设局网站发布html wordpress
  • 小型玩具企业网站建设初期阶段任务档案网站的建设方案
  • 网站建设系统公司网站建设礻首选金手指
  • 微网站模板免费下载网络商城营业执照经营范围
  • 睢县做网站南宁企业建站系统
  • 网站案例展示怎么做手机商城是什么意思
  • 做网站从哪里买域名工信部网站备案流程
  • 淘宝客网站做的好的wordpress没有文章导航
  • 室内设计公司 网站建设asp网站好还是php网站好
  • 黑龙江省建设安全监督网站建站基础
  • 松江老城做网站建筑工程公司简介
  • 注册网站入口x wordpress 视差 主题
  • wordpress托管建站安徽建筑大学城市建设学院网站
  • 网站 开发逻辑网站建设价格制定的方法
  • 张家界建设网站珠海网站建设方案优化
  • 网站设计相似侵权吗怎么建企业网站
  • qq钓鱼网站中国企业信息网
  • 黔南州住房和城乡建设局网站软件开发过程五个步骤
  • 潍坊制作网站软件怎么做网站原型
  • 做标书有哪些好网站天水网站开发
  • wrix 网站开发智能建造师证书有用吗