📄 calendar.js
字号:
returnValue = a[2] + "-" + appendZero(a[1]) + "-" + appendZero(a[0]);
returnValue += " " + appendZero(h) +":"+ appendZero(m) + ":" + appendZero(s);
}
else
alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
}
WebCalendar.objExport.value = returnValue;
hiddenCalendar();
}
else
{
alert("你设定的日期输出位置不对!\r\n\r\n请重新定义 WebCalendar.objExport !");
}
}
function returnCurDate() //根据日期格式等返回当前日期
{
var yy = new Date().getFullYear(),mm = new Date().getMonth() +1,dd = new Date().getDate();
var h = new Date().getHours(), m = new Date().getMinutes(), s = new Date().getSeconds();
if(WebCalendar.objExport)
{
var returnValue;
if(WebCalendar.format == "yyyyMMdd" || WebCalendar.format == "yyyyMMddHHmmss")
//eos标准格式
{
returnValue = yy + appendZero(mm) + appendZero(dd);
if(WebCalendar.timeShow == true)
{
returnValue += appendZero(h) + appendZero(m) + appendZero(s);
}
}
else if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(WebCalendar.format) ||
/^(y{4})(-|\/)(M{1,2})(-|\/)(d{1,2}) HH:mm:ss$/.test(WebCalendar.format))
//"-","/"间隔格式
{
var d;
if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(WebCalendar.format))
d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2})$/);
else
d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2}) HH:mm:ss$/);
if(d==null)
{
alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
return false;
}
var flag = d[3].length==2 || d[4].length==2; //判断返回的日期格式是否要补零
returnValue = flag ? yy +d[2]+ appendZero(mm) +d[2]+ appendZero(dd) : yy +d[2]+ mm +d[2]+ dd;
if(WebCalendar.timeShow == true)
{
returnValue += flag ? " "+ appendZero(h) +":"+ appendZero(m) +":"+ appendZero(s) : " "+ h +":"+ m +":"+ s;
}
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(WebCalendar.format) ||
/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/.test(WebCalendar.format))
//中文格式
{
var d;
if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(WebCalendar.format))
d = WebCalendar.format.match(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/);
else
d = WebCalendar.format.match(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/);
if(d==null)
{
alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
return false;
}
var flag = d[3].length==2 || d[5].length==2; //判断返回的日期格式是否要补零
returnValue = flag ? yy + "年" + appendZero(mm) + "月" + appendZero(dd) + "日" : yy + "年" + mm + "月" + dd + "日";
if(WebCalendar.timeShow == true)
{
var h = WebCalendar.thisHour, m = WebCalendar.thisMinute, s = WebCalendar.thisSecond;
returnValue += flag ? appendZero(h) +"时"+ appendZero(m) + "分" + appendZero(s) + "秒" : h +"时"+ m + "分" + s + "秒";
}
}
else
//默认的返回格式
{
if(/^(y{4})(-)(M{1,2})\2(d{1,2}) HH:mm:ss$/.test(WebCalendar.format))
{
var h = WebCalendar.thisHour, m = WebCalendar.thisMinute, s = WebCalendar.thisSecond;
returnValue = yy + "-" + mm + "-" + ss;
returnValue += " " + appendZero(h) +":"+ appendZero(m) + ":" + appendZero(s);
}
else
alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
}
WebCalendar.objExport.value = returnValue;
hiddenCalendar();
}
else
{
alert("你设定的日期输出位置不对!\r\n\r\n请重新定义 WebCalendar.objExport !");
}
}
function document.onclick()
{
if(WebCalendar.eventSrc != window.event.srcElement)
hiddenCalendar();
}
/**
*此函数把yyyMMdd或yyyyMMddHHmmss转成各种支持的格式
*参数说明:
* data:待转换的日期
* format:需要转换成的日期格式
*
*/
function formatSpecial(data,format)
{
if(WebCalendar.isOpen != true)
{
if(arguments[1] == undefined || arguments[1] == "undefined")
WebCalendar.format = "yyyy-MM-dd HH:mm:ss";
else
WebCalendar.format = arguments[1];
if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(WebCalendar.format))
{
WebCalendar.dateReg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
WebCalendar.timeShow = false;
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(WebCalendar.format))
{
WebCalendar.dateReg = /^(\d{4})年(\d{1,2})月(\d{1,2})日$/;
WebCalendar.timeShow = false;
}
else if(WebCalendar.format=="yyyyMMdd")
{
WebCalendar.dateReg = /^(\d{4})(\d{2})(\d{2})$/;
WebCalendar.timeShow = false;
}
else if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2}) (HH:mm:ss)$/.test(WebCalendar.format))
{
WebCalendar.dateReg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
WebCalendar.timeShow = true;
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/.test(WebCalendar.format))
{
WebCalendar.dateReg = /^(\d{4})年(\d{1,2})月(\d{1,2})日(\d{1,2})时(\d{1,2})分(\d{1,2})秒$/;
WebCalendar.timeShow = true;
}
else if(WebCalendar.format=="yyyyMMddHHmmss")
{
WebCalendar.dateReg = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/;
WebCalendar.timeShow = true;
}
else
{
WebCalendar.format = "yyyy-MM-dd HH:mm:ss";
WebCalendar.dateReg = /^(\d{4})(-|\/)(\d{2})\2(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
WebCalendar.timeShow = true;
}
var returnValue;
//alert(this.id.substr(8));
//alert(WebCalendar.day[this.id.substr(8)]);
//var a = WebCalendar.day[this.id.substr(8)].split("/");
var a=new Array();
a[2]=data.substr(0,4);
a[1]=data.substr(4,2);
a[0]=data.substr(6,2);
if(WebCalendar.format == "yyyyMMdd" || WebCalendar.format == "yyyyMMddHHmmss")
//eos标准格式
{
returnValue = a[2] + appendZero(a[1]) + appendZero(a[0]);
if(WebCalendar.timeShow == true)
{
var h = data.substr(8,2);
var m = data.substr(10,2);
var s = data.substr(12,2);
returnValue += appendZero(h) + appendZero(m) + appendZero(s);
}
}
else if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(WebCalendar.format) ||
/^(y{4})(-|\/)(M{1,2})(-|\/)(d{1,2}) HH:mm:ss$/.test(WebCalendar.format))
//"-","/"间隔格式
{
var d;
if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(WebCalendar.format))
d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2})$/);
else
d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2}) HH:mm:ss$/);
if(d==null)
{
// alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
return data;
}
var flag = d[3].length==2 || d[4].length==2; //判断返回的日期格式是否要补零
returnValue = flag ? a[2] +d[2]+ appendZero(a[1]) +d[2]+ appendZero(a[0]) : a[2] +d[2]+ a[1] +d[2]+ a[0];
if(WebCalendar.timeShow == true)
{
var h = data.substr(8,2);
var m = data.substr(10,2);
var s = data.substr(12,2);
returnValue += flag ? " "+ appendZero(h) +":"+ appendZero(m) +":"+ appendZero(s) : " "+ h +":"+ m +":"+ s;
}
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(WebCalendar.format) ||
/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/.test(WebCalendar.format))
//中文格式
{
var d;
if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(WebCalendar.format))
d = WebCalendar.format.match(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/);
else
d = WebCalendar.format.match(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/);
if(d==null)
{
//alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
return data;
}
var flag = d[3].length==2 || d[5].length==2; //判断返回的日期格式是否要补零
returnValue = flag ? a[2] + "年" + appendZero(a[1]) + "月" + appendZero(a[0]) + "日" : a[2] + "年" + a[1] + "月" + a[0] + "日";
//returnValue = a[2] + "年" + a[1] + "月" + a[0] + "日";
if(WebCalendar.timeShow == true)
{
var h = data.substr(8,2);
var m = data.substr(10,2);
var s = data.substr(12,2);
returnValue += flag ? appendZero(h) +"时"+ appendZero(m) + "分" + appendZero(s) + "秒" : h +"时"+ m + "分" + s + "秒";
//returnValue += h +"时"+ m + "分" + s + "秒";
}
}
else
//默认的返回格式
{
if(/^(y{4})(-)(M{1,2})\2(d{1,2}) HH:mm:ss$/.test(WebCalendar.format))
{
var h = data.substr(8,2);
var m = data.substr(10,2);
var s = data.substr(12,2);
returnValue = a[2] + "-" + appendZero(a[1]) + "-" + appendZero(a[0]);
returnValue += " " + appendZero(h) +":"+ appendZero(m) + ":" + appendZero(s);
}
else
return data;
//alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !");
}
return returnValue;
}
}
/**
*此函数把各种支持的格式转成yyyMMdd或yyyyMMddHHmmss
*参数说明:
* data:待转换的日期
* format:待转换日期的格式
*
*/
function formatDefault(data,format)
{
if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2})$/.test(format))
{
return data.substr(0,4)+data.substr(5,2)+data.substr(8,2);
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)$/.test(format))
{
return data.substr(0,4)+data.substr(5,2)+data.substr(8,2);
}
else if(WebCalendar.format=="yyyyMMdd")
{
return data;
}
else if(/^(y{4})(-|\/)(M{1,2})\2(d{1,2}) (HH:mm:ss)$/.test(format))
{return data.substr(0,4)+data.substr(5,2)+data.substr(8,2)+data.substr(11,2)+data.substr(14,2)+data.substr(17,2);
WebCalendar.dateReg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
WebCalendar.timeShow = true;
}
else if(/^(y{4})(年)(M{1,2})(月)(d{1,2})(日)(HH时mm分ss秒)$/.test(format))
{
return data.substr(0,4)+data.substr(5,2)+data.substr(8,2)+data.substr(11,2)+data.substr(14,2)+data.substr(17,2);
}
else if(format=="yyyyMMddHHmmss")
{ return data
}
else
{
return data.substr(0,4)+data.substr(5,2)+data.substr(8,2)+data.substr(11,2)+data.substr(14,2)+data.substr(17,2);
}
}
//-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -