package com.xg.supermarket.utils;
import com.xg.supermarket.config.ConstantsConfig;
import com.xg.supermarket.exception.BizException;
import tk.mybatis.mapper.util.StringUtil;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
public static Date getDate(String str){
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");// 这里要与时间字符串的格式一样即可,否则报错
if(StringUtil.isEmpty(str)){
return null;
}
try {
return dateFormat.parse(str);
} catch (ParseException e) {
throw new BizException("时间格式参数不正确,yyyy-MM-dd");
}
}
public static String toDate(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
/**
* 日期是本月的第几天
*
* @param date
* 天
* @return 当前天数
* @throws ParseException
* 数据转换异常
*/
public static String getMostDay(String date) throws ParseException {
// 当天日期是本月的第几天
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date nowDay = format.parse(date);
Calendar ca = Calendar.getInstance();
ca.setTime(nowDay);
int num = ca.get(Calendar.DAY_OF_MONTH);
String time = String.valueOf(num);
return time;
}
/**
* 获取日期在当月天数
*
* @param date
* 天
* @return 当月天数
* @throws Exception
* 异常
*/
public static String getMonthDay(String date) throws Exception {
// 当前月最大日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dates = sdf.parse(date);// String-->Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(dates);// 设置日历时间
int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
String mostDate = String.valueOf(day);
return mostDate;
}
/**
* 当年第一天
*
* @param date
* 日期
* @return 天
* @throws Exception
* 异常
*/
public static String getThisYear(String date) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format3 = new SimpleDateFormat("yyyy");
Date time = format3.parse(date);
String time1 = format3.format(time);
Date startTime = format.parse(time1 + "-01-01");
String dates = format.format(startTime);
return dates;
}
/**
* 当月第一天
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getFirstDayToMonth(String date) throws ParseException {
// 获取截止当前天数
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Date nowDay = format.parse(date);
String time = format.format(nowDay);
String firstDay = time + "-01";
return firstDay;
}
/**
* 当年第一天
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getFirstDay(String date) {
// 获取截止当前天数
SimpleDateFormat format = new SimpleDateFormat("yyyy");
Date nowDay = null;
try {
nowDay = format.parse(date);
} catch (ParseException e) {
throw new BizException("日期转换异常");
}
String time = format.format(nowDay);
String firstDay = time + "-01-01";
return firstDay;
}
/**
* 获取日期到年初的天数
*
* @param date
* 天
* @return 天数
* @throws Exception
* 异常
*/
public static int getDayCount(String date) throws Exception {
// 获取截止当前天数
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String year = date.substring(0, ConstantsConfig.CUT_OUT);
String starttime = year + "-01-01 00:00:00";
String endtime = date + " 00:00:00";
Date d1 = format.parse(starttime);
Date d2 = format.parse(endtime);
long s1 = d1.getTime();
long s2 = d2.getTime();
int days = (int) ((s2 - s1) / ConstantsConfig.EVERYDAY_SECOND);
return days;
}
/**
* 月底到年初的天数
*
* @param date
* 天
* @return 天
* @throws Exception
* 异常
*/
public static int getYearCount(String date) throws Exception {
String count = getMonthDay(date);
String firstDay = getFirstDay(date);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM");
long startTime = format.parse(firstDay).getTime();
long endTime = format2.parse(date).getTime();
String string = format2.format(endTime);
Date dates = format.parse(string + "-" + count);
long endMonthTime = dates.getTime();
long dayMonth = (endMonthTime - startTime) / ConstantsConfig.EVERYDAY_SECOND;
return (int) dayMonth;
}
/**
* 获取给定日起前一天
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getYesterDay(String date) throws ParseException {
// 获取给定日起过去15天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date dateTemp = sdf.parse(date);
cal.setTime(dateTemp);
cal.add(Calendar.DATE, ConstantsConfig.MINUS_1);
Date dates = cal.getTime();
String yesterDay = sdf.format(dates);
return yesterDay;
}
/**
* 获取给定日起前一周
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getLastWeekDay(String date) throws ParseException {
// 获取给定日起过去15天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date dateTemp = sdf.parse(date);
cal.setTime(dateTemp);
cal.add(Calendar.DATE, ConstantsConfig.MINUS_7);
Date dates = cal.getTime();
String yesterDay = sdf.format(dates);
return yesterDay;
}
/**
* 获取给定日起过去15天
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getLastFifthDay(String date) throws ParseException {
// 获取给定日起过去15天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date dateTemp = sdf.parse(date);
cal.setTime(dateTemp);
cal.add(Calendar.DATE, ConstantsConfig.MINUS_15); // -15
Date dates = cal.getTime();
String lastFifthDay = sdf.format(dates);
return lastFifthDay;
}
/**
* 获取给定日起一个月
*
* @param date
* 天
* @return 天
* @throws ParseException
* 异常
*/
public static String getLastMonthDay(String date) throws ParseException {
// 获取给定日起过去15天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
Date dateTemp = sdf.parse(date);
cal.setTime(dateTemp);
cal.add(C
没有合适的资源?快使用搜索试试~ 我知道了~
超市收银管理系统-毕业设计.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共970个文件
js:413个
html:212个
css:113个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 154 浏览量
2024-04-22
18:04:22
上传
评论
收藏 9.32MB ZIP 举报
温馨提示
超市收银管理系统-毕业设计
资源推荐
资源详情
资源评论
![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)
![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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
共 970 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d7864c98224046ec9a7f43fa6207c84e_qq_51320133.jpg!1)
生瓜蛋子
- 粉丝: 3829
- 资源: 6140
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的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)