package com.bytecub.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.*;
/**
* 有关 <code>Date</code> 处理的工具类
*
* @author hanxiaoqiang
*/
public class DateUtil {
public final static long ONE_DAY_SECONDS = 86400;
public final static String shortFormat = "yyyyMMdd";
public final static String longFormat = "yyyyMMddHHmmss";
public final static String webFormat = "yyyy-MM-dd";
public final static String webMonth = "yyyy-MM";
public final static String webDay = "MM-dd";
public final static String timeFormat = "HHmmss";
public final static String monthFormat = "yyyyMM";
public final static String chineseDtFormat = "yyyy年MM月dd日";
public final static String newFormat = "yyyy-MM-dd HH:mm:ss";
public final static String newDayFormat = "yyyy-MM-dd 00:00:00";
public final static String endDayFormat = "yyyy-MM-dd 23:59:59";
public final static String noSecondFormat = "yyyy-MM-dd HH:mm";
public final static String dateTimeWithZone = "yyyy-MM-dd'T'HH:mm:ss.SSSX";
public final static String dateTimeWithZoneZ = "yyyy-MM-dd'T'HH:mm:ss.SSS";
public final static String dayFormat = "yyyy/MM/dd";
public final static String yearFormat = "yyyy";
public final static String month = "MM";
public final static String second = "ss";
public final static String timeFormat2 = "HH:mm:ss";
public final static String timeFormat_HH_MM = "HH:mm";
public final static String TOMORROW_CH = "明天";
public final static long ONE_DAY_MILL_SECONDS = 86400000;
public final static String currentTimeZone = "GMT+8";
public final static String chinaTime = "MM时:mm分:ss秒";
public final static String chinaDate = "yyyy年MM月dd日 HH时:mm分:ss秒";
public final static String[] weekArr = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
public final static Integer DAYS_A_MONTH = 30;
public final static Integer DAYS_A_WEEK = 7;
public final static Integer DAYS_THREE_MONTHS = DAYS_A_MONTH * 3;
/**
* 日期路径 即年/月/日 如2018/08/08
*/
public static final String datePath()
{
Date now = new Date();
return DateFormatUtils.format(now, "yyyy/MM/dd");
}
public static String formatDateTimeWithZone(Date date) {
return DateUtil.format(date, dateTimeWithZone) + ":00";
}
/**
* 获取当前时间的指定格式
*
* @param pattern
* @return String
*/
public static String getNow(String pattern) {
return formatDate(Calendar.getInstance(), pattern);
}
/**
* 获取当前时间
*
* @return
*/
public static Date currentDate() {
return new Date();
}
/**
* 获取当前时间的指定格式
*
* @param pattern
* @return String
*/
public static Date getDate(String pattern) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
return formatter.parse(pattern);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 日期转字符串
*
* @param calendar 日历类型
* @param pattern 格式字符串
* @return String 格式化后的字符串
*/
public static String formatDate(Calendar calendar, String pattern) {
if (StringUtils.isEmpty(pattern)) {
pattern = webFormat;
}
return DateFormatUtils.format(calendar, pattern);
}
public static DateFormat getNewDateFormat(String pattern) {
DateFormat df = new SimpleDateFormat(pattern);
df.setLenient(false);
return df;
}
public static String format(Date date, String format) {
if (date == null) {
return "";
}
return new SimpleDateFormat(format).format(date);
}
public static Date parseDateNoTime(String sDate) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(shortFormat);
if ((sDate == null) || (sDate.length() < shortFormat.length())) {
throw new ParseException("length too little", 0);
}
if (!StringUtils.isNumeric(sDate)) {
throw new ParseException("not all digit", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateNoTime(String sDate, String format) throws ParseException {
if (StringUtils.isBlank(format)) {
throw new ParseException("Null format. ", 0);
}
DateFormat dateFormat = new SimpleDateFormat(format);
if ((sDate == null) || (sDate.length() < format.length())) {
throw new ParseException("length too little", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateNoTimeWithDelimit(String sDate, String delimit)
throws ParseException {
sDate = sDate.replaceAll(delimit, "");
DateFormat dateFormat = new SimpleDateFormat(shortFormat);
if ((sDate == null) || (sDate.length() != shortFormat.length())) {
throw new ParseException("length not match", 0);
}
return dateFormat.parse(sDate);
}
public static Date parseDateLongFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(longFormat);
Date d = null;
if ((sDate != null) && (sDate.length() == longFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
}
public static Date parseDateNewFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(newFormat);
Date d = null;
if ((sDate != null) && (sDate.length() == newFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
}
public static String getStringByFormat(Date date, String format) {
try {
return new SimpleDateFormat(format).format(date);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 计算当前时间几小时之后的时间
*
* @param date
* @param hours
* @return
*/
public static Date addHours(Date date, long hours) {
return addMinutes(date, hours * 60);
}
/**
* 计算当前时间几分钟之后的时间
*
* @param date
* @param minutes
* @return
*/
public static Date addMinutes(Date date, long minutes) {
return addSeconds(date, minutes * 60);
}
/**
* @param date1
* @param secs
* @return
*/
public static Date addSeconds(Date date1, long secs) {
return new Date(date1.getTime() + (secs * 1000));
}
/**
* 判断输入的字符串是否为合法的小时
*
* @param hourStr
* @return true/false
*/
public static boolean isValidHour(String hourStr) {
if (!StringUtils.isEmpty(hourStr) && StringUtils.isNumeric(hourStr)) {
int hour = new Integer(hourStr).intValue();
if ((hour >= 0) && (hour <= 23)) {
return true;
}
}
return false;
}
/**
* 判断输入的字符串是否为合法的分或秒
*
* @param
* @return true/false
*/
public static boolean isValidMinuteOrSecond(String str) {
if (!StringUtils.isEmpty(str) && StringUtils.isNumeric(str)) {
int hour = new Integer(str).intValue();
if ((hour >= 0) && (hour <= 59)) {
return
没有合适的资源?快使用搜索试试~ 我知道了~
bytecub-物联网通讯平台
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共473个文件
java:414个
xml:39个
jpg:5个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 21 浏览量
2023-05-10
10:42:46
上传
评论
收藏 834KB ZIP 举报
温馨提示
基于java8,SpringBoot2.3.6 ElasticSearch 7.6.2,redis,MySQL 5.6/5.7的物联网通讯平台。使用习惯和市面上的物联网云平台一致
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 473 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/de50ac10e30e41b89db28203f97239be_qq_41701956.jpg!1)
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6823
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)