date.plugin.js 日期插件
//定义命名空间
var DatePlugin;
if (!DatePlugin) DatePlugin = {}; /*整理时间:2015-05-28*/ var defaultFormat = "yyyy-MM-dd"; //默认的日期格式
var totalDefaultFormat = "yyyy-MM-dd hh:mm:ss";
var pointFormat = "yyyy.MM.dd";
var slashFormat = "MM/dd/yyyy";
var textFormat = "yyyy年MM月dd日";
var totalTextFormat = "yyyy年MM月dd日hh小时mm分ss秒";
var noFormat = "yyyyMMdd"; /* 转换时间格式 */
Date.prototype.Format = function (DateFormat) {
var o = {
"M+": this.getMonth() + , //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + ) / ), //quarter
"S": this.getMilliseconds() //millisecond
}
var format = (DateFormat) ? DateFormat : defaultFormat;
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$, (this.getFullYear() + "").substr( - RegExp.$.length));
} for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$, RegExp.$.length == ? o[k] : ("" + o[k]).substr(("" + o[k]).length));
}
}
return format;
} /* 增加天数 */
Date.prototype.addDay = function (num) {
this.setDate(this.getDate() + num);
return this;
}; /* 增加月数 */
Date.prototype.addMonth = function (num) {
var tempDate = this.getDate();
this.setMonth(this.getMonth() + num);
if (tempDate != this.getDate()) this.setDate();
return this;
}; /* 增加年数 */
Date.prototype.addYear = function (num) {
var tempDate = this.getDate();
this.setYear(this.getYear() + num);
if (tempDate != this.getDate()) this.setDate();
return this;
}; /*
*获取某日日期 可传日期格式参数
*默认格式:YYYY-MM-DD
*/
DatePlugin.exactDate = { /* 获取今日日期 */
getTodayDate:function (DateFormat) {
var myDate = new Date();
return myDate.Format(DateFormat);
}, /* 获取明日日期 */
getTomorrowDate: function (DateFormat) {
var myDate = new Date().addDay();
return myDate.Format(DateFormat);
}, /* 获取昨天日期 */
getYesterdayDate: function (DateFormat) {
var myDate = new Date().addDay(-);
return myDate.Format(DateFormat);
}
} /*
*统计某个时间段的周数或天数或者返回值是数字
*/
DatePlugin.staticDate = { /*统计今年某月的天数*/
getMonthDays: function (Month) {
var myMonth = Month;
var now = new Date(); //当前日期
var nowYear = now.getFullYear(); //当前年
var monthStartDate = new Date(nowYear, myMonth, );
var monthEndDate = new Date(nowYear, myMonth + , );
var days = (monthEndDate - monthStartDate) / ( * * * );
return days;
}, /*统计某年某月总周数*/
getWeekCounts: function (year, month) {
var firstDate = new Date(year, month, );
var first = firstDate.getDay();
var endDate = ; // 周六
var firstWeekday = endDate - first + ;
var lastDay = this.getMonthDays(month) - firstWeekday;
return Math.ceil(lastDay / ) + ;
}, /*获取当前月*/
getCurrentMonth:function () {
var now = new Date(); //当前日期
var nowDayOfWeek = now.getDay(); //今天本周的第几天
var nowDay = now.getDate(); //当前日
var nowMonth = now.getMonth() + ; //当前月
var nowYear = now.getFullYear(); //当前年
return nowMonth;
}
} DatePlugin.calculDate = { /*计算几天前或几天后的日期*/
getTrunsAddDay: function (date,num,DateFormat) {
var targetday_milliseconds = date.getTime() + * * * * num;
var resultDate = new Date(date.setTime(targetday_milliseconds));
return resultDate.Format(DateFormat);
}, /*获得本月的开始日期*/
getMonthStartDate: function (DateFormat) {
var now = new Date(); //当前日期
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getFullYear(); //当前年
var monthStartDate = new Date(nowYear, nowMonth, );
return monthStartDate.Format(DateFormat);
}, /*获得本月的结束日期*/
getMonthEndDate: function (DateFormat) {
var now = new Date(); //当前日期
var nowDayOfWeek = now.getDay(); //今天本周的第几天
var nowDay = now.getDate(); //当前日
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getFullYear(); //当前年
var monthEndDate = new Date(nowYear, nowMonth, DatePlugin.staticDate.getMonthDays(nowMonth));
return monthEndDate.Format(DateFormat);
}, /*获得某个月的开始日期*/
getMonthStart: function (currDate, DateFormat) {
var now = new Date(currDate); //当前日期
var nowMonth = parseInt(now.getMonth()); //当前月
var nowYear = now.getFullYear(); //当前年 var monthStartDate = new Date(nowYear, nowMonth, );
return monthStartDate.Format(DateFormat);
}, /*获得某个月的结束日期*/
getMonthEnd: function (currDate, DateFormat) {
var now = new Date(currDate); //当前日期
var nowMonth = parseInt(now.getMonth()); //当前月
var nowYear = now.getFullYear(); //当前年 var monthEndDate = new Date(nowYear, nowMonth, DatePlugin.staticDate.getMonthDays(nowMonth));
return monthEndDate.Format(DateFormat);
}, /*获得当天开始前一个月的开始日期*/
getBeforeMonth: function (DateFormat) {
var now = new Date(); //当前日期
var nowMonth = now.getMonth() - ; //当前月
var nowYear = now.getFullYear(); //当前年
var monthDate;
if (nowMonth != -) {
monthDate = new Date(nowYear, nowMonth);
} else {
monthDate = new Date(nowYear - , );
}
return monthDate.Format(DateFormat);
}, /*获取最近一周开始时间*/
getBeforeOneWeekStartDate: function (DateFormat) {
var nowdate = new Date();
return oneweekkdate = this.getTrunsAddDay(nowdate, -, DateFormat);
}, /*获取三个月以内的起始时间*/
getBeforeThreeMonthStartDate: function (DateFormat) {
var nowdate = new Date();
return threemonthdate = this.getTrunsAddDay(nowdate, -, DateFormat);
}, /*获取一个月以内的起始时间*/
getBeforeOneMonthStratDate: function (DateFormat) {
var nowdate = new Date();
return threemonthdate = this.getTrunsAddDay(nowdate, -, DateFormat);
} } DatePlugin.otherDate = { /*ISO8601*/
parseISO8601:function(dateStringInRange) {
var isoExp = /^\s*(\d{})-(\d\d)-(\d\d)\s*$/,
date = new Date(NaN), month,
parts = isoExp.exec(dateStringInRange); if (parts) {
month = +parts[];
date.setFullYear(parts[], month - , parts[]);
if (month != date.getMonth() + ) {
date.setTime(NaN);
}
}
return date;
}, /*处理日期格式兼容浏览器方法*/
newDate:function(str) {
str = str.split('-');
var date = new Date();
date.setUTCFullYear(str[], str[] - , str[]);
date.setUTCHours(, , , );
return date;
}
}
date.plugin.js 日期插件的更多相关文章
- js日期插件bootstrap-datetimepicker的使用
js日期插件——bootstrap-datetimepicker的使用心得: 在大多说的web项目中,都有日期选择器的使用.如果自己写一个日期选择器的话,费时又费力,而且不一定能写出来_(:3 」∠) ...
- js 日期插件 datepicker
点击图片出现 时间 ,增加一个点击事件 <label for="" class="width80">创建日:</label> < ...
- 【vue学习】vue中怎么引用laydate.js日期插件
此贴意在解决一个妹子的问题 https://q.cnblogs.com/q/101462 下载js包 http://www.layui.com/laydate/ 将laydate下载的包解压放入sta ...
- javascript Date format(js日期格式化) (转)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- [转]javascript Date format(js日期格式化)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- javascript Date format(js日期格式化)
这个用这比较爽,记录一下// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年( ...
- [荐]javascript Date format(js日期格式化)
cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date ...
- validate.plugin.js 验证插件
/*编写时间:2015-6-4*/ (function ($) { $.fn.isValidate = function (obj) { if ($(this).val()!="" ...
- laydate JS日期插件
原文出处 简要介绍 你是时候换一款日期控件了,而layDate非常愿意和您成为工作伙伴.她致力于成为全球最用心的web日期支撑,为国内外所有从事web应用开发的同仁提供力所能及的动力.她基于原生Jav ...
随机推荐
- visual studio 2010运行速度提速
前段时间为了一个项目而把VS2008换成了VS2010,结果原本就不堪重负的本本跑起VS2010来那更是慢得没话说,于是看了遍VS2010选项,又从网上到处找资料找优化方法,总算使我的VS2010跑得 ...
- Splay树再学习
队友最近可能在学Splay,然后让我敲下HDU1754的题,其实是很裸的一个线段树,不过用下Splay也无妨,他说他双旋超时,单旋过了,所以我就敲来看下.但是之前写的那个Splay越发的觉得不能看,所 ...
- POJ2406 Power Strings KMP算法
给你一个串s,如果能找到一个子串a,连接n次变成它,就把这个串称为power string,即a^n=s,求最大的n. 用KMP来想,如果存在的话,那么我每次f[i]的时候退的步数应该是一样多的 譬 ...
- java基础知识回顾之java Thread类学习(五)--java多线程安全问题(锁)同步的前提
这里举个例子讲解,同步synchronized在什么地方加,以及同步的前提: * 1.必须要有两个以上的线程,才需要同步. * 2.必须是多个线程使用同一个锁. * 3.必须保证同步中只能有一个线程在 ...
- POJ2299Ultra-QuickSort
http://poj.org/problem?id=2299 题意 : 排序,求排序次数,本来以为用冒泡可以搞定,事实上,那么大的数据以及一个TLE告诉我,会超时......... 思路 : 问了一下 ...
- 解决maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e.错误
POM文件报错maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supp ...
- [转]Ubuntu 常用快捷键10个
转自:http://www.linuxeden.com/html/news/20100613/103374.html 1.前一个后一个工作区的切换 如果你经常使用工作区,那你就可以用Ctrl + Al ...
- 【Linux高频命令专题(13)】cat
概述 常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. cat主要有三大功能: 1.一次显示整个文件:cat filename 2.从键盘创建一 ...
- Xamarin.Android 入门之:Xamarin快速入门
一. 准备工作 1.新建一个项目取名为phoneword 2.在项目创建好之后,让我们展开“Resources”文件夹然后找到并打开该文件夹下的“layout”文件夹,双击main.axml在Andr ...
- servlet会话技术:Cookie
什么是会话会话可以简单理解为:用户开一个浏览器访问某个网站,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话.会话过程中需要解决的一些问题每个用户在使用浏览器与服务器进 ...