首页 > 代码库 > time
time
///$.twoDates("startdate",‘enddate‘,3); $.extend({ setTwoDates: function (startinputid, endinputid, difference) { var year = 0; var today = ""; var mydate = new Date(); var mymonth = mydate.getMonth() + 1; var myday = mydate.getDate(); var myyear = mydate.getFullYear(); year = (myyear > 200) ? myyear : 1900 + myyear; if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; } if (myday >= 10) { myday = myday; } else { myday = "0" + myday; } today = year + ‘-‘ + mymonth + ‘-‘ + myday; $("#" + endinputid).val(today); var enddate = mydate.valueOf(); enddate = enddate - difference * 24 * 60 * 60 * 1000; mydate = new Date(enddate); var year = 0; var today = ""; var mymonth = mydate.getMonth() + 1; var myday = mydate.getDate(); var myyear = mydate.getFullYear(); year = (myyear > 200) ? myyear : 1900 + myyear; if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; } if (myday >= 10) { myday = myday; } else { myday = "0" + myday; } today = year + ‘-‘ + mymonth + ‘-‘ + myday; $("#" + startinputid).val(today); } }) ///$("#elementid").setDefaultDate(); $.fn.extend({ setDefaultDate: function (datetype) { var day = 0; var month = 0; var year = 0; var today = ""; mydate = new Date(); mydate.setTime(mydate.getTime() - 24 * 60 * 60 * 1000); mymonth = mydate.getMonth()+1; myday = mydate.getDate(); myyear = mydate.getFullYear(); year = (myyear > 200) ? myyear : 1900 + myyear; if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; } if (myday >= 10) { myday = myday; } else { myday = "0" + myday; } switch (datetype) { case "day": today = year + ‘-‘ + mymonth + ‘-‘ + myday; break; case "month": today = year + ‘-‘ + mymonth; break; case "year": today = year; default: break; } $(this).val(today); } })
time
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。