public final class TimeUtil {private static final Logger LOGGER = LoggerFactory.getLogger(TimeUtil.class);private TimeUtil() {}/*** 获取当前时间(系统时间)距离特定时间(如18:00:00)的间隔,结果可能为正,亦可为负* 间隔 >=0: 表示当前时间未到达(或刚好到达)设定的时间* 间隔 <0: 表示当前时间已超过设定的时间* 有异常时抛出** @param time 字符串形式的时间,如 09:00:00 (不能写作 9:00:00)* @return long*/public static long getTimeDiffWithMills(String time) {try {// HH:mm:ssDateTimeFormatter localTimeFormatter = DateTimeFormatter.ofPattern(ConstantUtil.DATE_TIME_FORMAT_GENERAL_INFO);LocalTime planTime = LocalTime.parse(time, localTimeFormatter);LocalTime now = LocalTime.now();return Duration.between(now, planTime).toMillis();} catch (Exception e) {LOGGER.error("error message: 获取当前时间(系统时间)距离特定时间 <{}> 的间隔异常,原因是 <{}>", time, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 依据设定时间及其任务执行类型获取调整后的监听时间** @param time            String    字符串形式的时间,如 09:00:00 (不能写作 9:00:00)* @param taskExecuteType AnalysisEnumEntity.TaskExecuteType    任务执行类型* @return long 调整后的毫秒时间*/public static long getAdjustedTimeDiffWithMillsByType(String time, AnalysisEnumEntity.TaskExecuteType taskExecuteType) {try {long initialDiff = getTimeDiffWithMills(time);switch (taskExecuteType) {// 定时执行case TASK_EXECUTE_TYPE_TIMED:if (initialDiff >= 0) {return initialDiff;} else {return initialDiff + ConstantUtil.ONE_DAY_IN_MILLISECONDS;}// 立即执行case TASK_EXECUTE_TYPE_IMMEDIATELY:return 0;default:LOGGER.error("error message: 暂不支持的任务执行类型 <{}>", taskExecuteType.getLabel());return 0;}} catch (Exception e) {LOGGER.error("error message: 依据任务类型 <{}> 获取调整后毫秒时间异常,原因是 <{}>", taskExecuteType.getLabel(), String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}public static long getTime(String time) {DateFormat dateFormat = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_YEAR);try {Date curDate = dateFormat.parse(time);return curDate.getTime() - System.currentTimeMillis();} catch (ParseException e) {LOGGER.error("error message: 时间转换出错,原因是 <{}>", String.valueOf(e));return 0;}}/*** 将 Instant 时间转换为 Date** @param instant Instant* @return Date* @throws BusinessException 转换异常*/public static Date instantToDate(Instant instant) throws BusinessException {try {return new Date(instant.toEpochMilli());} catch (Exception e) {LOGGER.error("error message: Instant 时间转换为 Date,失败,原因", e);throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}public static long getAdjustedTime(String time, AnalysisEnumEntity.TaskExecuteType taskExecuteType) {long initialDiff = getTime(time);switch (taskExecuteType) {// 定时执行case TASK_EXECUTE_TYPE_TIMED:if (initialDiff >= 0) {return initialDiff;} else {return initialDiff + ConstantUtil.ONE_DAY_IN_MILLISECONDS;}// 立即执行case TASK_EXECUTE_TYPE_IMMEDIATELY:return 0;default:return 0;}}/*** 将 unix 时间戳转换为 相应时区时间* 注意:当发生异常时,返回空字符串,未抛出异常** @param instant    Instant    Instant 时间* @param zoneIdType SystemEnumEntity.ZoneIdType    自定义时区类型* @return String*/public static String instantToString(Instant instant, SystemEnumEntity.ZoneIdType zoneIdType) {if (null == instant || null == zoneIdType) {LOGGER.debug("debug message: Instant 时间 <{}> 或 时区信息 <{}> 无效", instant, zoneIdType);return ConstantUtil.SPECIAL_CHARACTER_EMPTY;}try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ConstantUtil.DATE_TIME_FORMAT_GENERAL).withZone(ZoneId.of(zoneIdType.getLabel()));return dateTimeFormatter.format(instant);} catch (Exception e) {LOGGER.error("error message: Instant 时间 <{}> 转换为特定字符串格式时间异常,原因是 <{}>", instant, String.valueOf(e));return ConstantUtil.SPECIAL_CHARACTER_EMPTY;}}/*** 将日期格式形如 yyyy-MM-dd HH:mm:ss 的字符串转为 Instant格式形如yyyy-MM-ddTHH:mm:ssZ 的字符串** @param dateTime String 日期格式形如 yyyy-MM-dd HH:mm:ss 的字符串* @return Instant格式形如yyyy-MM-ddTHH:mm:ssZ 的字符串* @throws BusinessException 日期转换异常*/public static String dateStringToInstantString(String dateTime) throws BusinessException {try {dateTime = dateTime.toUpperCase();if (dateTime.contains("T") && dateTime.contains("Z")) {return dateTime;}Instant instant = TimeUtil.stringToInstant(dateTime, SystemEnumEntity.ZoneIdType.ZONE_ID_TYPE_UTC, false);return instant.toString();} catch (Exception e) {LOGGER.error("error message: 日期时间 <{}> 转换为 Instant 时间异常,原因是 <{}>", dateTime, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 将 String 时间转换为 相应时区下的时间戳** @param dateTime           String* @param zoneIdType         SystemEnumEntity.ZoneIdType* @param dateTimeFormatFlag boolean*                           True-Instant格式的字符串,形如"2021-11-25T14:00:13Z"*                           False-非Instant格式的字符串,形如"2021-11-25 14:00:13"* @return Instant* @throws BusinessException 抛出异常*/public static Instant stringToInstant(String dateTime,SystemEnumEntity.ZoneIdType zoneIdType,boolean dateTimeFormatFlag) throws BusinessException {if (StringUtil.isEmpty(dateTime) || null == zoneIdType) {LOGGER.error("error message: 日期时间 <{}> 或 时区信息 <{}> 无效", dateTime, zoneIdType);throw new BusinessException(GuiErrorCode.ACCESS_PARAMETER_INVALID);}try {if (dateTimeFormatFlag) {return LocalDateTime.ofInstant(Instant.parse(dateTime), ZoneId.of(zoneIdType.getLabel())).toInstant(ZoneOffset.UTC);} else {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ConstantUtil.DATE_TIME_FORMAT_GENERAL);LocalDateTime localDateTime = LocalDateTime.parse(dateTime, dateTimeFormatter);return localDateTime.atZone(ZoneId.of(zoneIdType.getLabel())).toInstant();}} catch (Exception e) {LOGGER.error("error message: 字符串格式时间 <{}> 转换为 Instant 异常,原因是 <{}>", dateTime, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 将 Instant 时间转换为 LocalDateTime** @param instant    Instant   Instant 时间* @param zoneIdType SystemEnumEntity.ZoneIdType 时区信息* @return LocalDateTime* @throws BusinessException 转换异常*/public static LocalDateTime instantToLocalDateTime(Instant instant, SystemEnumEntity.ZoneIdType zoneIdType) throws BusinessException {try {return LocalDateTime.ofInstant(instant, ZoneId.of(zoneIdType.getLabel()));} catch (Exception e) {LOGGER.error("error message: Instant 时间 <{}> 转换为 LocalDateTime 异常,原因是 <{}>", instant, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 将日期转为特定格式的字符串日期** @param date       Date 待转换的日期* @param format     String 时间格式字符串* @param zoneIdType SystemEnumEntity.ZoneIdType 时区信息* @return String 字符串格式的时间* @throws BusinessException 自定义异常*/public static String dateToString(Date date, String format, SystemEnumEntity.ZoneIdType zoneIdType) throws BusinessException {try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);return dateTimeFormatter.format(date.toInstant().atZone(ZoneId.of(zoneIdType.getLabel())).toLocalDate());} catch (Exception e) {LOGGER.error("error message: 日期 <{}> 转换为 String 格式 <{}> 日期时间异常,原因是 <{}>", date, format, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 将特定格式的字符串日期转为日期形式** @param str        Date* @param dateFormat String* @return String* @throws BusinessException 自定义异常*/public static LocalDate stringToLocalDate(String str, String dateFormat) throws BusinessException {try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat);return LocalDate.parse(str, dateTimeFormatter);} catch (Exception e) {LOGGER.error("error message: String 格式日期 <{}> 转换为 LocalDate 格式 <{}> 日期时间异常,原因是 <{}>", str, dateFormat, String.valueOf(e));throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 获取当前日期的特定格式** @param timeFormat String 日期格式* @return String* @throws BusinessException 异常*/public static String getCurrentDate(String timeFormat) throws BusinessException {try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timeFormat);return dateTimeFormatter.format(LocalDateTime.now());} catch (Exception e) {LOGGER.error("error message: 获取当前日期的特定格式,数据异常,原因:<{}>", String.valueOf(e));throw new BusinessException((SystemErrorCode.DATE_CONVERT_FAILED));}}/*** 获取当前日期前的若干天的特定格式** @param beforeDays int 天数* @param timeFormat String 日期格式* @return String* @throws BusinessException 异常*/public static String getCurrentDateBeforeSpecialDays(int beforeDays, String timeFormat) throws BusinessException {try {// 获取基于当前日期之前的特定日期LocalDate currentDate = LocalDate.now().minusDays(beforeDays);DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timeFormat);return dateTimeFormatter.format(currentDate);} catch (Exception e) {LOGGER.error("error message: 获取当前日期前的若干天的特定格式,数据异常,原因:<{}>", String.valueOf(e));throw new BusinessException((SystemErrorCode.DATE_CONVERT_FAILED));}}/*** 依据指标同步频率获取任务开始日期** @param actualIndexFrequency AnalysisEnumEntity.IndexFrequency 指标同步频率* @return String*/public static String getTaskStartDate(AnalysisEnumEntity.IndexFrequency actualIndexFrequency) {String date;switch (actualIndexFrequency) {case INDEX_FREQUENCY_WEEK:date = getCurrentDateBeforeSpecialDays(7,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_TEN_DAYS:date = getCurrentDateBeforeSpecialDays(10,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_MONTH:date = getCurrentDateBeforeSpecialDays(30,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_QUARTER:date = getCurrentDateBeforeSpecialDays(90,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_HALF_YEAR:date = getCurrentDateBeforeSpecialDays(180,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_YEAR:date = getCurrentDateBeforeSpecialDays(360,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;case INDEX_FREQUENCY_HALF_MONTH:date = getCurrentDateBeforeSpecialDays(15,ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;// 其它情况默认为每日default:date = getCurrentDate(ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);break;}return date;}/*** 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss** @param dateDate Date* @return String*/public static String dateToStrLong(Date dateDate) {SimpleDateFormat formatter = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_INFO);return formatter.format(dateDate);}/*** 将短时间格式时间转换为字符串 yyyy-MM-dd** @param dateDate Date* @return String*/public static String dateToStr(Date dateDate) {SimpleDateFormat formatter = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);return formatter.format(dateDate);}/*** 将短时间格式时间转换为字符串 yyyy-MM-dd 当前时间加1分钟** @param dateDate Date* @return String*/public static String date(Date dateDate) {LocalDateTime now = date2LocalDateTime(dateDate);LocalDateTime localDateTime = now.plusMinutes(1);DateTimeFormatter formatters = DateTimeFormatter.ofPattern(ConstantUtil.DATE_TIME_FORMAT_GENERAL);return formatters.format(localDateTime);}/*** Date 转 LocalDateTime** @param date Date* @return LocalDateTime*/public static LocalDateTime date2LocalDateTime(Date date) {return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();}/*** LocalDateTime 转 Date** @param localDateTime LocalDateTime* @return Date*/public static Date localDateTimeDate(LocalDateTime localDateTime) {return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());}/*** 将短时间格式时间转换为字符串 yyyyMMdd** @param dateDate String* @return String*/public static String dateString(Date dateDate) {SimpleDateFormat formatter = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_TWO);return formatter.format(dateDate);}/*** 将短时间格式字符串转换为时间 yyyy-MM-dd** @param strDate String* @return Date*/public static Date strToDate(String strDate) {SimpleDateFormat formatter = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_THREE);ParsePosition pos = new ParsePosition(0);return formatter.parse(strDate, pos);}/*** 将短时间格式字符串转换为时间 yyyyMMdd** @param strDate String* @return Date*/public static Date strDate(String strDate) {SimpleDateFormat formatter = new SimpleDateFormat(ConstantUtil.DATE_TIME_FORMAT_GENERAL_WITHOUT_HOUR_TWO);ParsePosition pos = new ParsePosition(0);return formatter.parse(strDate, pos);}/*** 校验字符串是否为合法的日期格式** @param strDate String* @param format  String* @return boolean*/public static boolean isValidDate(String strDate, String format) {try {SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);simpleDateFormat.setLenient(false);return null != simpleDateFormat.parse(strDate);} catch (ParseException e) {LOGGER.error("error message: 校验字符串是否为合法的日期格式,数据异常,原因:", e);return false;}}/*** 判断日期是否有效** @param date       String,日期* @param dateFormat String,日期格式* @return boolean True-日期有效 False-日期无效*/public static boolean isDateValid(String date, String dateFormat) {if (StringUtil.isEmpty(date) || StringUtil.isEmpty(dateFormat)) {return false;}try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat.replace("y", "u")).withResolverStyle(ResolverStyle.STRICT);return LocalDate.parse(date, dateTimeFormatter) != null;} catch (Exception e) {LOGGER.error("error message: 日期 <{}> 验证不通过,原因", date, e);return false;}}/*** 获取形如 20210819、2021-08-19、19:19等 形式的当前日期(含时间)** @param dateTimeFormat String,日期格式* @return String 当前日期(含时间),形如 20210819、2021-08-19、19:19等*/public static String getCurrentLocalDateWithSpecialFormat(String dateTimeFormat) {// 线程不安全 'new SimpleDateFormat(dateTimeFormat).format(Calendar.getInstance().getTime())'return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateTimeFormat));}/*** str 类型的日期比较** @param str1           String 日期1* @param str2           String 日期2* @param dateTimeFormat String 日期格式* @return int -2:待对比的数据异常 -1: 日期1 < 日期2; 0: 日期1 = 日期2; 1: 日期1 > 日期2*/public static int dateCompare(String str1, String str2, String dateTimeFormat) {try {if (StringUtil.isEmpty(str1) || StringUtil.isEmpty(str2)) {return -2;}LocalDate date1 = stringToLocalDate(str1, dateTimeFormat);LocalDate date2 = stringToLocalDate(str2, dateTimeFormat);return date1.compareTo(date2);} catch (Exception e) {LOGGER.error("error message: 日期比较异常,原因:<{}>", String.valueOf(e));throw new BusinessException((SystemErrorCode.DATE_CONVERT_FAILED));}}/*** 将 unix 时间戳转换为 相应时区时间** @param instant       Instant* @param zoneIdType    SystemEnumEntity.ZoneIdType* @param dateFormatter String* @return String*/public static String instantToString(Instant instant,SystemEnumEntity.ZoneIdType zoneIdType,String dateFormatter) {if (null == instant ||null == zoneIdType ||StringUtil.isEmpty(dateFormatter)) {return "";}try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormatter).withZone(ZoneId.of(zoneIdType.getLabel()));return dateTimeFormatter.format(instant);} catch (Exception e) {LOGGER.error("error message: 时间转换异常,原因是 ", e);return "";}}/*** 将 String 时间转换为 相应时区下的时间戳** @param dateTime      String* @param zoneIdType    SystemEnumEntity.ZoneIdType* @param dateFormatter String* @return Instant*/public static Instant stringToInstant(String dateTime,SystemEnumEntity.ZoneIdType zoneIdType,String dateFormatter) throws BusinessException {if (StringUtil.isEmpty(dateTime) ||null == zoneIdType ||StringUtil.isEmpty(dateFormatter)) {throw new BusinessException(GuiErrorCode.ACCESS_PARAMETER_INVALID);}try {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormatter);LocalDateTime localDateTime = LocalDateTime.parse(dateTime, dateTimeFormatter);return localDateTime.atZone(ZoneId.of(zoneIdType.getLabel())).toInstant();} catch (Exception e) {LOGGER.error("error message: 字符串格式时间 <{}> 转换为 Instant 异常,原因是", dateTime, e);throw new BusinessException(SystemErrorCode.DATE_CONVERT_FAILED);}}/*** 校验时间间隔** @param start          String 时间间隔开始时间* @param end            String 时间间隔结束时间* @param dateTimeFormat String 时间格式* @return boolean True-时间间隔无效 False—时间间隔有效*/public static boolean isIntervalInvalid(String start, String end, String dateTimeFormat) {if (StringUtil.isEmpty(start)|| StringUtil.isEmpty(end)|| StringUtil.isEmpty(dateTimeFormat)) {LOGGER.error("error message: 待校验时间间隔参数无效 <start> <{}>, <end> <{}>, <dateTimeFormat> <{}>", start, end, dateTimeFormat);return true;}try {if (!isDateValid(start, dateTimeFormat)|| !isDateValid(end, dateTimeFormat)) {LOGGER.error("error message: 待间间隔开始时间 <start> <{}>, 时间间隔结束时间 <end> <{}> 不是对应的日期格式 <dateTimeFormat> <{}>", start, end, dateTimeFormat);return true;}return dateCompare(start, end, dateTimeFormat) > 0;} catch (Exception e) {LOGGER.error("error message: 待校验校验时间间隔参数异常,原因:", e);return true;}}/*** 将 Date 转为 LocalDate** @param date Date* @return java.time.LocalDate;*/public static LocalDate dateToLocalDate(Date date) {return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();}/*** 将 LocalDateTime 转换为对应的格式的字符串** @param localDateTime  LocalDateTime* @param dateTimeFormat String 时间格式* @return String* @throws BusinessException 异常*/public static String localDateTimeToString(LocalDateTime localDateTime, String dateTimeFormat) throws BusinessException {try {if (null == localDateTime|| StringUtil.isEmpty(dateTimeFormat)) {LOGGER.error("error message: 待转换日期 <{}> , 时间格式 <{}> 参数无效", localDateTime, dateTimeFormat);throw new BusinessException((SystemErrorCode.DATE_CONVERT_FAILED));}DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormat);return dateTimeFormatter.format(localDateTime);} catch (Exception e) {LOGGER.error("error message: LocalDateTime  <{}>  转换为字符串格式 <{}>异常,原因是 <{}>", localDateTime, dateTimeFormat, e);throw new BusinessException((SystemErrorCode.DATE_CONVERT_FAILED));}}/*** 日期范围查询参数校验** @param rangeDate      RangeDateVO 日期范围查询VO* @param dateTimeFormat String 时间格式 如 yyyyMMdd* @param bothRequired   boolean True- 日期范围开始日期与结束日期都必须指定 False-日期范围开始日期与结束日期二者可选* @return boolean True- 日期范围查询参数无效 False- 日期范围查询参数有效*/public static boolean isRangeDateInvalid(RangeDateVO rangeDate, String dateTimeFormat, boolean bothRequired) {try {if (null == rangeDate|| StringUtil.isEmpty(dateTimeFormat)) {LOGGER.error("error message: 待校验日期范围 <rangeDate> <{}>, <dateTimeFormat> <{} >参数无效", rangeDate, dateTimeFormat);return true;}// 开始日期与结束日期两者都必须指定的场合if (bothRequired) {return isIntervalInvalid(rangeDate.getStartDate(), rangeDate.getEndDate(), dateTimeFormat);}// 开始日期与结束日期两者两者可选else {if (StringUtil.isEmpty(rangeDate.getStartDate())&& StringUtil.isEmpty(rangeDate.getEndDate())) {return true;} else if (!StringUtil.isEmpty(rangeDate.getStartDate())&& StringUtil.isEmpty(rangeDate.getEndDate())) {return !isValidDate(rangeDate.getStartDate(), dateTimeFormat);} else if (StringUtil.isEmpty(rangeDate.getStartDate())&& !StringUtil.isEmpty(rangeDate.getEndDate())) {return !isValidDate(rangeDate.getEndDate(), dateTimeFormat);} else {return isIntervalInvalid(rangeDate.getStartDate(), rangeDate.getEndDate(), dateTimeFormat);}}} catch (Exception e) {LOGGER.error("error message: 待校验期范围异常, 原因是:", e);return true;}}}

主要是针对时间格式,相互转换以及校验的工具类,希望对大家有所帮助!!!

时间工具类、Instant、date、LocalDate、String、LocalDateTime 相互转换相关推荐

  1. java8的时间工具类_JAVA8日期工具类

    /*** Java8日期时间工具类 * *@authorJourWon * @date 2020/12/13*/ public classLocalDateUtils {/*** 显示年月日时分秒,例 ...

  2. Java中 LocalDate、LocalTime、LocalDateTime三个时间工具类的使用介绍

    Java中 LocalDate.LocalTime.LocalDateTime三个时间工具类的使用介绍 一.背景: 之前在做项目的过程中,对日期时间类没有一个系统的了解,总是在用的时候去搜索一下,解决 ...

  3. Java8 ,LocalDate,LocalDateTime处理日期和时间工具类,

    Java8 ,LocalDate,LocalDateTime处理日期和时间工具类 日期格式化 1.获取今天的日期 2.在Java 8 中获取年.月.日信息 3.在Java 8 中处理特定日期 4.在J ...

  4. 基于jdk8 LocalDate系列API的全新实用时间工具类

    基于jdk8 LocalDate系列API的实用时间工具类, 已经经过多个项目的考验与完善, 包含个人心得体会 欢迎转载,转载请注明网址:https://blog.csdn.net/qq_419102 ...

  5. 重学Java8新特性(四) : 日期时间API、LocalDateTime、DateTimeFormatter、开发中时间工具类(常用)

    文章目录 一.JDK8中日期时间API的介绍 1.1.LocalDate.LocalTime.LocalDateTime的使用 2.2.Instant类的使用 2.3.DateTimeFormatte ...

  6. Android Date时间工具类

    需求: 安卓常用的时间工具类,长时间转换.星期判断.时间延后n天.提前n天.得到当前分.小时.时间差等 代码: package com.hsq.pos.util;import java.text.Pa ...

  7. JDK8新特性:Lambda表达式、Stream流、日期时间工具类

    重要特性: 可选类型声明:不需要声明参数类型,编译器可以统一识别参数值. 可选的参数圆括号:一个参数无需定义圆括号,但多个参数需要定义圆括号. 可选的大括号:如果主体包含了一个语句,就不需要大括号. ...

  8. 分享一个Joda-Time日期时间工具类

    写在前面 在JDK1.8之前,处理日期和时间的方式比较单一,Java中提供了Calendar来处理日期,但是过程较为繁琐. 但是在JDK1.8之后,Java更新了time包提供了LocalDate,L ...

  9. java8彩蛋_随笔,JDK8的新时间工具类

    jdk8带来了新的时间工具类,主要有LocalDateTime(时间+日期) ,LocalDate(日期) 以及LocalTime(时间).下面来看看常用用法在新的工具类上如何使用. 1. 获取当前的 ...

最新文章

  1. AndroidStudio git 提交代码,创建分支,合并分支,回滚版本,拉取代码
  2. 解决报错:gpg: keyserver receive failed: No dirmngr
  3. 如果对象为空,java函数String.valueOf(Object obj)返回null字符串
  4. onenote怎么同步到电脑_详解onenote保存与同步④:本地笔记奇葩的丢失经历
  5. 染色(树链剖分 洛谷-P2486)
  6. java不支持发行版本12_主要发行版本后Java开发人员应使用的15种工具
  7. Springboot初次学习
  8. StringBuffer的基本用法 2101 0311
  9. android 4g获取mac地址,Android手机获取Mac地址的几种方法
  10. 从Gradient Descent 到 Stochastic Gradient Descent(SGD)
  11. 为什么大家越来越重视大数据的发展?
  12. 违反计算机信息网络国际联网安全,网络安全合规指引题库:计算机信息网络国际联网,是指中华人民共和国境内的计算机信息网络为实现信息的国际交流,同外国的计算机信息网络相联接。()...
  13. 莫队算法小介绍——看似暴力的莫队算法
  14. 小知识------SATA
  15. 用ESP8266实现 手机控制车库门开关
  16. 2023年湖南中专单招报名流程
  17. type=“module“ 你了解,但 type=“importmap“ 你知道吗
  18. 赛龙代小权终审无罪释放,重燃创业之心
  19. 七十行代码教你使用 python ffmpeg 压缩视频,再也不用担心视频过大了
  20. iOS与Android对比

热门文章

  1. 【技术文档】centernet(姿态估计)
  2. Linux-------线程安全
  3. 多链路5G组网方案-支持国密算法的5G安全组网方案
  4. 阻止创建“迅雷下载“目录
  5. 玩转华为数据中心交换机系列 | 配置动态LACP模式的链路聚合示例
  6. oracle rman crosscheck 命令
  7. Automation Anywhere视频教程
  8. 把ubuntu安装在U盘的教程之一:制作U盘启动盘
  9. HDU5142 NPY and arithmetic progression BestCoder Round #23 1002
  10. DevExtreme UI框架在可视化应用程序Nvisual中的实践应用