jQuery时间验证和转换为标准格式的时间格式

前端之家收集整理的这篇文章主要介绍了jQuery时间验证和转换为标准格式的时间格式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近整理文档发现一篇文章,可以将时间转换成标准格式的时间,发出来给大家参考一下。

10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "-"// "月" + (date.getDate() < 10 ? "0" + date.getDate() : date .getDate()); return datetime; },/** * 格式化日期(含时间"00:00:00") */ formatterDate2 : function(date) { var datetime = date.getFullYear() + "-"// "年" + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "-"// "月" + (date.getDate() < 10 ? "0" + date.getDate() : date .getDate()) + " " + "00:00:00"; return datetime; },/** * 格式化去日期(含时间) */ formatterDateTime : function(date) { var datetime = date.getFullYear() + "-"// "年" + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "-"// "月" + (date.getDate() < 10 ? "0" + date.getDate() : date .getDate()) + " " + (date.getHours() < 10 ? "0" + date.getHours() : date .getHours()) + ":" + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date .getMinutes()) + ":" + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date .getSeconds()); return datetime; },/** * 时间比较{结束时间大于开始时间} */ compareDateEndTimeGTStartTime : function(startTime,endTime) { return ((new Date(endTime.replace(/-/g,"/"))) > (new Date( startTime.replace(/-/g,"/")))); },/** * 验证开始时间合理性{开始时间不能小于当前时间{X}个月} */ compareRightStartTime : function(month,startTime) { var now = formatterDayAndTime(new Date()); var sms = new Date(startTime.replace(/-/g,"/")); var ems = new Date(now.replace(/-/g,"/")); var tDayms = month * 30 * 24 * 60 * 60 * 1000; var dvalue = ems - sms; if (dvalue > tDayms) { return false; } return true; },/** * 验证开始时间合理性{结束时间不能小于当前时间{X}个月} */ compareRightEndTime : function(month,endTime) { var now = formatterDayAndTime(new Date()); var sms = new Date(now.replace(/-/g,"/")); var ems = new Date(endTime.replace(/-/g,"/")); var tDayms = month * 30 * 24 * 60 * 60 * 1000; var dvalue = sms - ems; if (dvalue > tDayms) { return false; } return true; },/** * 验证开始时间合理性{结束时间与开始时间的间隔不能大于{X}个月} */ compareEndTimeGTStartTime : function(month,startTime,endTime) { var sms = new Date(startTime.replace(/-/g,/** * 获取最近几天[开始时间和结束时间值,时间往前推算] */ getRecentDaysDateTime : function(day) { var daymsTime = day * 24 * 60 * 60 * 1000; var yesterDatsmsTime = this.getCurrentMsTime() - daymsTime; var startTime = this.longMsTimeConvertToDateTime(yesterDatsmsTime); var pastDate = this.formatterDate2(new Date(startTime)); var nowDate = this.formatterDate2(new Date()); var obj = { startTime : pastDate,endTime : nowDate }; return obj; },/** * 获取今天[开始时间和结束时间值] */ getTodayDateTime : function() { var daymsTime = 24 * 60 * 60 * 1000; var tomorrowDatsmsTime = this.getCurrentMsTime() + daymsTime; var currentTime = this.longMsTimeConvertToDateTime(this.getCurrentMsTime()); var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime); var nowDate = this.formatterDate2(new Date(currentTime)); var tomorrowDate = this.formatterDate2(new Date(termorrowTime)); var obj = { startTime : nowDate,endTime : tomorrowDate }; return obj; },/** * 获取明天[开始时间和结束时间值] */ getTomorrowDateTime : function() { var daymsTime = 24 * 60 * 60 * 1000; var tomorrowDatsmsTime = this.getCurrentMsTime() + daymsTime; var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime); var theDayAfterTomorrowDatsmsTime = this.getCurrentMsTime()+ (2 * daymsTime); var theDayAfterTomorrowTime = this.longMsTimeConvertToDateTime(theDayAfterTomorrowDatsmsTime); var pastDate = this.formatterDate2(new Date(termorrowTime)); var nowDate = this.formatterDate2(new Date(theDayAfterTomorrowTime)); var obj = { startTime : pastDate,endTime : nowDate }; return obj; } };

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

原文链接:https://www.f2er.com/jquery/41061.html

猜你在找的jQuery相关文章