js:合同-已知起始日期、年限,自动计算截止日期
dateAddYear('2016-01-01', '3') ;//返回:2018-12-31
浏览器:ie11,ff 46.0.1(成功)360v8.1(急速模式,成功)
浏览器:360v8.1(兼容模式,失败)
一。代码:
//date: 日期字符串yyyy-MM-dd,如:2016-02-14
//years:年份,正整数字符串
//返回日期字符串yyyy-MM-dd,如:2016-02-14
function dateAddYear(date, years) {
var now = new Date(date);
var intYear = now.getFullYear() + parseInt(years);
var intMonth = now.getMonth() + 1; //正常的月份,
var intDay = now.getDate() - 1; //日期-1
if (intDay == 0) {
intMonth--; //减少一个月
if (intMonth == 0) {
intYear--; //0:减少一年
intMonth = 12;
intDay = 31;
}
else if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) {
intDay = 30; //4,6,9,11:30天
}
else if (intMonth == 2) {
intDay = 28; //2:28/29
if (intYear % 4 == 0) {
intDay = 29;
}
} else {
intDay = 31; //1,3,5,7,8,10,12 :31天
}
}
var strMonth = (intMonth) < 10 ? "0" + (intMonth).toString() : (intMonth).toString();
var strDay = (intDay) < 10 ? "0" + (intDay).toString() : (intDay).toString();
var strEndDate = intYear + "-" + strMonth + "-" + strDay;
return strEndDate;
}
二。相关方法、函数说明
// var myDate = new Date();
// myDate.getYear(); //获取当前年份(2位)
// myDate.getFullYear(); //获取完整的年份(4位,1970-????)
// myDate.getMonth(); //获取当前月份(0-11,0代表1月)
// myDate.getDate(); //获取当前日(1-31)
// myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
// myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
// myDate.getHours(); //获取当前小时数(0-23)
// myDate.getMinutes(); //获取当前分钟数(0-59)
// myDate.getSeconds(); //获取当前秒数(0-59)
// myDate.getMilliseconds(); //获取当前毫秒数(0-999),目前是13位整数
// myDate.toLocaleDateString(); //获取当前日期,如:2016年6月17日
// myDate.toLocaleTimeString(); //获取当前时间,如:11:41:24
// myDate.toLocaleString(); //获取当前日期时间,如:2016年6月17日 11:41:24
js:合同-已知起始日期、年限,自动计算截止日期的更多相关文章
- 用js写已知abc+cba = 1333,其中a、b、c均为一位数,编程求出满足条件的a、b、c所有组合。
<!--<script type="text/javascript"> //已知abc+cba = 1333,其中a.b.c均为一位数,编程求出满足条件的a.b. ...
- 已知一个日期和天数, 求多少天后的日期(是那个超时代码的AC版)
#include <stdio.h> #include <string.h> ; int judge_year(int x) { == || x % == && ...
- easyui datebox 时间限制,datebox开始时间限制结束时间,datebox截止日期比起始日期大
easyui datebox 时间限制,datebox开始时间限制结束时间,datebox截止日期比起始日期大 >>>>>>>>>>> ...
- 已知起始点,获取每段等距离途经点的经纬度(用百度js api作)
已知两个中文地址,自动规划路径,获取路径上每个3公里的点的经纬度 <html> <head> <meta http-equiv="Content-Type&qu ...
- JS计算日期加天数后的日期(起始日期+有效天数=截至日期)
/** * 优惠券有效期 * startDate:起始日期 * valueTime:有效天数 */ function transferCouponValueTime(startDate,valueTi ...
- js获取当前时间戳与日期比较
如何用javascript获取当前时间戳: 复制代码 代码示例: 方法1: var timestamp = date.parse(new date()); 结果:1280977330000 方法2: ...
- 对象布局已知时 C++ 对象指针的转换时地址调整
在我调试和研究 netscape 系浏览器插件开发时,注意到了这个问题.即,在对象布局已知(即对象之间具有继承关系)时,不同类型对象的指针进行转换(不管是隐式的从下向上转换,还是强制的从上到下转换)时 ...
- 2015 前端[JS]工程师必知必会
2015 前端[JS]工程师必知必会 本文摘自:http://zhuanlan.zhihu.com/FrontendMagazine/20002850 ,因为好东东西暂时没看懂,所以暂时保留下来,供以 ...
- Node.js:实现知乎(www.zhihu.com)模拟登陆,获取用户关注主题
前一段时间,在瞎看看 Node.js,便研究通过 Node.js 实现知乎模拟登陆.相信,有很多网站有登陆权限设置,如若用户未登陆,将会跳转至首页提醒用户登陆,无法浏览部分页面. 如若是 b/s 架构 ...
随机推荐
- flash builder 4.7 debug via usb device iPhone 4s - device not found
http://forums.adobe.com/message/4865192 Please provide more info on the above issue: 1.What is the m ...
- 删除vector中的偶数元素,删除list中的奇数元素
#include<vector> #include<list> #include<iostream> using namespace std; int main() ...
- [013]函数重载--int*和void*的匹配优先级
同事去面试的时候的问题: 测试一下发现:在同时存在int*和void*的重载函数时,vs2010的环境下,优先匹配void* #include<iostream> using namesp ...
- eclipse+ADT 进行android应用签名详解
http://jojol-zhou.iteye.com/blog/719428 1.Eclipse工程中右键工程,弹出选项中选择 android工具-生成签名应用包: 2.选择需要打包的android ...
- 认识CoreData-多线程
CoreData使用相关的技术点已经讲差不多了,我所掌握的也就这么多了.... 在本篇文章中主要讲CoreData的多线程,其中会包括并发队列类型.线程安全等技术点.我对多线程的理解可能不是太透彻,文 ...
- 明天参加GDG devfest
明天就可以第二次去参加devfest了,还记得去年去的时候是个啥也听不懂的小白,希望今年能够收获更多,结识更多大牛和志同道合的伙伴.
- About gpref O(n2) --> O(1)
http://www.ibm.com/developerworks/cn/linux/l-gperf.html 命令行处理和 gperf 的作用 命令行处理一直以来都是软件开发中最容易被忽视的领域.几 ...
- javascript数据结构和算法[转]
字符串表示的数组 join() 和 toString() 函数返回数组的字符串表示.这两个函数通过将数组中的元素用逗号分隔符分割,返回字符串数组表示. 这里有个例子: var names = [&qu ...
- 详细讲解Android对自己的应用代码进行混淆加密防止反编译
1.查看项目中有没有proguard.cfg. 2.如果没有那就看看这个文件中写的什么吧,看完后将他复制到你的项目中. -optimizationpasses 5 -dontusemixedcasec ...
- LeetCode里有特色的问题存档
002* Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. F ...