let now = new Date(); //当前日期
let nowDayOfWeek = now.getDay()-1; //今天本周的第几天
let nowDay = now.getDate(); //当前日
let nowMonth = now.getMonth(); //当前月
let nowYear = now.getYear(); //当前年
nowYear += (nowYear < 2000) ? 1900 : 0; //
let lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
let lastYear = lastMonthDate.getFullYear();
let lastMonth = lastMonthDate.getMonth();
const dateRangeUtils ={
//格式化日期
formatDate:(date)=>{
let myYear = date.getFullYear();
let myMonth = date.getMonth() + 1;
let myWeekday = date.getDate();
if (myMonth < 10) {
myMonth = "0" + myMonth;
if (myWeekday < 10) {
myWeekday = "0" + myWeekday;
return (myYear + "-" + myMonth + "-" + myWeekday);
//获得某月的天数
getMonthDays:(myYear,myMonth)=>{
let monthStartDate = new Date(myYear, myMonth, 1);
let monthEndDate = new Date(myYear, myMonth + 1, 1);
let days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
return days;
//获得本季度的开始月份
getQuarterStartMonth:()=>{
let quarterStartMonth = 0;
if (nowMonth < 3) {
quarterStartMonth = 0;
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
if (nowMonth > 8) {
quarterStartMonth = 9;
return quarterStartMonth;
getCurrentDate:()=>{
let getCurrentDate = new Date(nowYear, nowMonth, nowDay);
return dateRangeUtils.formatDate(getCurrentDate)
getYesterdayDate:()=>{
let getYesterdayDate = new Date(nowYear, nowMonth, nowDay - 1);
return dateRangeUtils.formatDate(getYesterdayDate);
//获得本周的开始日期和结束日期
getCurrentWeekRange:()=>{
let timeRange = new Array();
let weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
let weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
timeRange.push(dateRangeUtils.formatDate(weekStartDate));
timeRange.push(dateRangeUtils.formatDate(weekEndDate));
return timeRange;
//获得上周的开始日期和结束日期
getLastWeekRange:()=> {
let timeRange = new Array();
let weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 7);
let weekEndDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek - 1);
timeRange.push(dateRangeUtils.formatDate(weekStartDate));
timeRange.push(dateRangeUtils.formatDate(weekEndDate));
return timeRange;
//获得本月的开始日期和结束时间
getCurrentMonthRange:()=> {
let timeRange = new Array();
let monthStartDate = new Date(nowYear, nowMonth, 1);
let monthEndDate = new Date(nowYear, nowMonth, dateRangeUtils.getMonthDays(nowYear,nowMonth));
timeRange.push(dateRangeUtils.formatDate(monthStartDate));
timeRange.push(dateRangeUtils.formatDate(monthEndDate));
return timeRange;
//获得上月开始时间和结束时间
getLastMonthRange:()=> {
let timeRange = new Array();
let lastMonthStartDate = new Date(lastYear, lastMonth, 1);
let lastMonthEndDate = new Date(lastYear, lastMonth, dateRangeUtils.getMonthDays(lastYear,lastMonth));
timeRange.push(dateRangeUtils.formatDate(lastMonthStartDate));
timeRange.push(dateRangeUtils.formatDate(lastMonthEndDate));
return timeRange;
//本季度的开始日期 结束日期
getCurrentQuarterRange:()=> {
let timeRange = new Array();
//本季度开始
let quarterStartDate = new Date(nowYear, dateRangeUtils.getQuarterStartMonth(), 1);
//本季度结束
let quarterEndMonth = dateRangeUtils.getQuarterStartMonth() + 2;
let quarterEndDate = new Date(nowYear, quarterEndMonth,
dateRangeUtils.getMonthDays(nowYear,quarterEndMonth));
timeRange.push(dateRangeUtils.formatDate(quarterStartDate));
timeRange.push(dateRangeUtils.formatDate(quarterEndDate));
return timeRange;
//上季度的第一天
getLastQuarterFirstDay:(year, month)=> {
let spring = 0; //春
let summer = 3; //夏
let fall = 6; //秋
let winter = 9; //冬
//月份从0-11
switch (month) {//季度的其实月份
case spring:
//如果是第一季度则应该到去年的冬季
year--;
month = winter;
break;
case summer:
month = spring;
break;
case fall:
month = summer;
break;
case winter:
month = fall;
break;
return new Date(year, month, 1);
* 得到上季度的起止日期
* **/
getLastQuarterRange:()=> {
//起止日期数组
let timeRange = new Array();
//获取当前时间
let currentDate = new Date(nowYear, nowMonth, nowDay);
//获得当前月份0-11
let currentMonth = currentDate.getMonth();
//获得当前年份4位年
let currentYear = currentDate.getFullYear();
//上季度的第一天
let priorSeasonFirstDay = dateRangeUtils.getLastQuarterFirstDay(currentYear, currentMonth);
//上季度的最后一天
let priorSeasonLastDay = new Date(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2, dateRangeUtils.getMonthDays(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2));
//添加至数组
timeRange.push(dateRangeUtils.formatDate(priorSeasonFirstDay));
timeRange.push(dateRangeUtils.formatDate(priorSeasonLastDay));
return timeRange;
//上半年开始时间
getPrevHalfYear:()=>{
let timeRange = new Array();
timeRange.push(nowYear + '-01-01');
timeRange.push(nowYear + '-06-30');
return timeRange;
//下半年开始时间
getNextHalfYear:()=>{
let timeRange = new Array();
timeRange.push(nowYear + '-07-01');
timeRange.push(nowYear + '-12-31');
return timeRange;
//全年开始时间结束时间
getCurrentYearRange:()=>{
let timeRange = new Array();
//获取当前时间
let currentDate = new Date(nowYear, nowMonth, nowDay);
//获得当前年份4位年
let currentYear = currentDate.getFullYear();
//本年第一天
let currentYearFirstDate = new Date(currentYear, 0, 1);
//本年最后一天
let currentYearLastDate = new Date(currentYear, 11, 31);
timeRange.push(dateRangeUtils.formatDate(currentYearFirstDate));
timeRange.push(dateRangeUtils.formatDate(currentYearLastDate));
return timeRange;
format:(date,fmt)=>{
let o = {
"M+" : date.getMonth()+1, //月份
"d+" : date.getDate(), //日
"h+" : date.getHours(), //小时
"m+" : date.getMinutes(), //分
"s+" : date.getSeconds(), //秒
"q+" : Math.floor((date.getMonth()+3)/3), //季度
"S" : date.getMilliseconds() //毫秒
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
for(let k in o) {
if(new RegExp("("+ k +")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
return fmt;
获取两个时间相邻的数组 type:目前可传"yyyy-MM-dd hh" "yyyy-MM-dd" "yyyy-MM"格式的时间
getTimeArr:(begin,end,type,interval)=>{
let arr=[];
let beginDate;
let endDate;
let msCount;
if(type=="yyyy-MM-dd hh"){//设置小时间隔
beginDate=new Date(begin+" 00:00");
endDate=new Date(end+" 23:59");
msCount=interval*60*60*1000; //1小时 2小时 3小时
}else if(type=="yyyy-MM-dd hh:mm"){//设置分钟间隔
beginDate=new Date(begin+" 00:00");
endDate=new Date(end+" 23:59");
msCount=interval*60*1000; //30分钟 10分钟 5分钟 15分钟
}else if(type=="yyyy-MM-dd"){//设置天间隔
beginDate=new Date(begin+" 00:00");
endDate=new Date(end+" 00:00");
msCount=interval*24*60*60*1000; //1天 2天 3天
}else if(type=="yyyy-MM"){//获取月间隔
let startDate=begin.split("-");
let endDate1=end.split("-");
let intervalMonth = (parseInt(endDate1[0]*12)+parseInt(endDate1[1])) - (parseInt(startDate[0]*12)+parseInt(startDate[1]));
arr=dateRangeUtils.getMonthArr(end,intervalMonth+1);
return arr;
}else if(type=="yyyy"){//获取年间隔
for(let i=parseInt(begin);i<=parseInt(end);i++){
arr.push(i.toString());
return arr;
let beginMs=beginDate.getTime();
let endMs=endDate.getTime();
for(let i=beginMs;i<=endMs;i+=msCount){
if(type=="yyyy-MM-dd hh"){
arr.push(dateRangeUtils.format(new Date(i),type)+":00");
}else if(type=="yyyy-MM-dd hh:mm"){
arr.push(dateRangeUtils.format(new Date(i),type));
else if(type=="yyyy-MM-dd"){
arr.push(dateRangeUtils.format(new Date(i),type));
return arr;
//得到最近n个月份的数组
getMonthArr:(sDate,n)=>{
let arr=[];
sDate=sDate.slice(0,7);
arr.push(sDate);
while(n>1){
arr.unshift(dateRangeUtils.getBeforMonth(sDate));
sDate=dateRangeUtils.getBeforMonth(sDate);
return arr;
getBeforMonth:(date)=>{
let lastMonth="";
let year=date.split("-")[0],month=date.split("-")[1];
if(month==1){
lastMonth=(year-1)+"-"+12;
}else{
lastMonth=year+"-"+(month-1<10?('0'+(month-1)):month-1);
return lastMonth;
export default dateRangeUtils;
/** * 获取对应的日期开始和结束时间 * @type {{convert: dateRangeUtils.convert}} */let now = new Date(); //当前日期let nowDayOfWeek = now.getDay()-1; //今天本周的第几天let nowDay = now.getDate(); //当前日let nowMonth = now.getMonth(); //当前月let nowYear = now.getYear(); //当前年now.
Dateutils是一个很好的计算系统
时间
的并且Android的sdk library(android.text.format.DateUtils)自带的库。
由于公司要求,
获取
到手机系统的
时间
差,即给一个long型的
时间
,即可得到系统格式的
时间
差。并且这个
时间
差有多语言化。Dateutils就是一个很好的工具,只要一句话。
1.
获取
时间
差
DateUtils.formatDateRang...
* 1.一下大部分(也可能是全部)date都可以换成calendar也就是日历
时间
* 2.calendar.get(Calendar.MONTH)
获取
的月比正常月份少一个月
* 3.calendar.get(Calen...
//定义
常用
变量-
public static final String DATE_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_FORMAT_YMD = "yyyy-MM-dd";
public static final String DATE_FORMAT_HMS = "HH:mm:ss";
pub...
2 //
获取
间隔天数
3 function getDays(day1, day2) {
4 //
获取
入参字符串形式日期的Date型日期
5 var st = day1....
var st = this.form5.abnormalStartDate // 开始
时间
var stsjc = new Date(st).getTime()/1000; // 将开始
时间
转换成
时间
戳
var ed = this.form5.abnormalEndDa...
1. 切片操作(如a_copy = a[:]):
时间
复杂度为O(n),其中n为
数组
的长度。
2. 使用copy()方法(如a_copy = a.copy()):
时间
复杂度为O(n),其中n为
数组
的长度。
因此,Python中的
数组
复制
时间
复杂度为O(n),其中n为
数组
的长度。
Failed to convert value of type ‘java.lang.String‘ to required type ‘java.time.LocalDate‘
spring boot 后端控制controller重复提交