// 增加天
function adddays(date,value)
{
date.setdate(date.getdate()+value);
}
// 增加月
function addmonths(date,value)
{
date.setmonth(date.getmonth()+value);
}
// 增加年
function addyears(date,value)
{
date.setfullyear(date.getfullyear()+value);
}
// 是否为今天
function istoday(date)
{
return isdateequals(date,new date());
}
// 是否为当月
function isthismonth(date)
{
return ismonthequals(date,new date());
}
// 两个日期的年是否相等
function ismonthequals(date1,date2)
{
return date1.getmonth()==date2.getmonth()&&date1.getfullyear()==date2.getfullyear();
}
// 判断日期是否相等
function isdateequals(date1,date2)
{
return date1.getdate()==date2.getdate()&&ismonthequals(date1,date2);
}
// 返回某个日期对应的月份的天数
function getmonthdaycount(date)
{
switch(date.getmonth()+1)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
return 31;
case 4:case 6:case 9:case 11:
return 30;
}
//feb:
date=new date(date);
var lastd=28;
date.setdate(29);
while(date.getmonth()==1)
{
lastd++;
adddays(date,1);
}
return lastd;
}
// 返回两位数的年份
function getharfyear(date)
{
var v=date.getyear();
if(v>9)return v.tostring();
return "0"+v;
}
// 返回月份(修正为两位数)
function getfullmonth(date)
{
var v=date.getmonth()+1;
if(v>9)return v.tostring();
return "0"+v;
}
// 返回日 (修正为两位数)
function getfulldate(date)
{
var v=date.getdate();
if(v>9)return v.tostring();
return "0"+v;
}
// 替换字符串
function replace(str,from,to)
{
return str.split(from).join(to);
}
// 格式化日期的表示
function formatdate(date,str)
{
str=replace(str,"yyyy",date.getfullyear());
str=replace(str,"mm",getfullmonth(date));
str=replace(str,"dd",getfulldate(date));
str=replace(str,"yy",getharfyear(date));
str=replace(str,"m",date.getmonth()+1);
str=replace(str,"d",date.getdate());
return str;
}
// 统一日期格式
function convertdate(str)
{
str=(str+"").replace(/^\s*/g,"").replace(/\s*$/g,""); // 去除前后的空白
var d;
if(/^[0-9]{8}$/.test(str)) // 20040226 -> 2004-02-26
{
d=new date(new number(str.substr(0,4)),new number(str.substr(4,2))-1,new number(str.substr(6,2)));
if(d.gettime())return d;
}
d=new date(str);
if(d.gettime())return d;
d=new date(replace(str,"-","/"));
if(d.gettime())return d;
return null;
}
js时间差函数
0
0
相关文章
为什么说javascript是单线程语言【教程】
如何使用 JavaScript 动态切换图像的显示与隐藏状态
javascript如何编写兼容不同浏览器的代码【教程】
javascript是什么_为什么它是前端开发的核心语言【教程】
如何在 Bootstrap 模态框中正确加载点击图片的 src
相关标签:
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。
54
2026.01.31
想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。
50
2026.01.31
想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。
12
2026.01.31
本合集详细介绍PHP运行环境的搭建与配置方法,涵盖Windows、Linux及Mac系统下的安装步骤、常见问题及解决方案。阅读专题下面的文章了解更多详细内容。
0
2026.01.31
本合集详细讲解PHP环境变量的设置方法,涵盖Windows、Linux及常见服务器环境配置技巧,助你快速掌握环境变量的正确配置。阅读专题下面的文章了解更多详细内容。
0
2026.01.31
热门下载
相关下载
精品课程
共39课时 | 4万人学习
共101课时 | 8.6万人学习
共39课时 | 3.2万人学习
最新文章




