// 增加天
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
相关文章
D3.js 甜甜圈图数据绑定与 Tooltip 正确实现指南
D3.js 饼图与环形图中正确绑定数据以实现 Tooltip 交互
javascript如何理解Web Workers_如何实现多线程【教程】
为什么选择JavaScript_它有哪些核心优势【教程】
javascript如何实现响应式设计与移动适配【教程】
相关标签:
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
本专题围绕 Archive of Our Own(AO3)官网入口展开,系统整理 AO3 最新可用官网地址、网页版访问方式、正确打开链接的方法,并详细讲解 AO3 中文界面设置、阅读语言切换及基础使用流程,帮助用户稳定访问 AO3 官网,高效完成中文阅读与作品浏览。
91
2026.02.02
本专题聚合极兔快递、京东快递、中通快递、圆通快递、韵达快递等主流物流平台的单号查询与运单追踪内容,重点解决单号查询、手机号查物流、官网入口直达、包裹进度实时追踪等高频问题,帮助用户快速获取最新物流状态,提升查件效率与使用体验。
27
2026.02.02
本专题系统讲解 Golang 在 WebAssembly(WASM)开发中的实践方法,涵盖 WASM 基础原理、Go 编译到 WASM 的流程、与 JavaScript 的交互方式、性能与体积优化,以及典型应用场景(如前端计算、跨平台模块)。帮助开发者掌握 Go 在新一代 Web 技术栈中的应用能力。
11
2026.02.02
本专题聚焦 PHP Swoole 扩展在高性能服务端开发中的应用,系统讲解协程模型、异步IO、TCP/HTTP/WebSocket服务器、进程与任务管理、常驻内存架构设计。通过实战案例,帮助开发者掌握 使用 PHP 构建高并发、低延迟服务端应用的工程化能力。
5
2026.02.02
本专题系统讲解 Java 通过 JNI 调用 C/C++ 本地代码的核心机制,涵盖 JNI 基本原理、数据类型映射、内存管理、异常处理、性能优化策略以及典型应用场景(如高性能计算、底层库封装)。通过实战示例,帮助开发者掌握 Java 与本地代码混合开发的完整流程。
5
2026.02.02
热门下载
相关下载
精品课程
共39课时 | 4万人学习
共101课时 | 8.7万人学习
共39课时 | 3.2万人学习
最新文章




