国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Jquery時(shí)間驗(yàn)證和轉(zhuǎn)換工具小例子

2024-05-06 15:48:21
字體:
供稿:網(wǎng)友
這篇文章介紹了Jquery時(shí)間驗(yàn)證和轉(zhuǎn)換工具小例子,有需要的朋友可以參考一下

復(fù)制代碼 代碼如下:


var TimeObjectUtil;
/**
* @title 時(shí)間工具類
* @note 本類一律違規(guī)驗(yàn)證返回false
* @author {boonyachengdu@gmail.com}
* @date 2013-07-01
* @formatter "2013-07-01 00:00:00" , "2013-07-01"
*/
TimeObjectUtil = {
/**
* 獲取當(dāng)前時(shí)間毫秒數(shù)
*/
getCurrentMsTime : function() {
var myDate = new Date();
return myDate.getTime();
},
/**
* 毫秒轉(zhuǎn)時(shí)間格式
*/
longMsTimeConvertToDateTime : function(time) {
var myDate = new Date(time);
return this.formatterDateTime(myDate);
},
/**
* 時(shí)間格式轉(zhuǎn)毫秒
*/
dateToLongMsTime : function(date) {
var myDate = new Date(date);
return myDate.getTime();
},
/**
* 格式化日期(不含時(shí)間)
*/
formatterDate : function(date) {
var datetime = date.getFullYear()
+ "-"http:// "年"
+ ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
+ (date.getMonth() + 1))
+ "-"http:// "月"
+ (date.getDate() < 10 ? "0" + date.getDate() : date
.getDate());
return datetime;
},
/**
* 格式化日期(含時(shí)間"00:00:00")
*/
formatterDate2 : function(date) {
var datetime = date.getFullYear()
+ "-"http:// "年"
+ ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
+ (date.getMonth() + 1))
+ "-"http:// "月"
+ (date.getDate() < 10 ? "0" + date.getDate() : date
.getDate()) + " " + "00:00:00";
return datetime;
},
/**
* 格式化去日期(含時(shí)間)
*/
formatterDateTime : function(date) {
var datetime = date.getFullYear()
+ "-"http:// "年"
+ ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
+ (date.getMonth() + 1))
+ "-"http:// "月"
+ (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;
},
/**
* 時(shí)間比較{結(jié)束時(shí)間大于開始時(shí)間}
*/
compareDateEndTimeGTStartTime : function(startTime, endTime) {
return ((new Date(endTime.replace(/-/g, "/"))) > (new Date(
startTime.replace(/-/g, "/"))));
},
/**
* 驗(yàn)證開始時(shí)間合理性{開始時(shí)間不能小于當(dāng)前時(shí)間{X}個(gè)月}
*/
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;
},
/**
* 驗(yàn)證開始時(shí)間合理性{結(jié)束時(shí)間不能小于當(dāng)前時(shí)間{X}個(gè)月}
*/
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;
},
/**
* 驗(yàn)證開始時(shí)間合理性{結(jié)束時(shí)間與開始時(shí)間的間隔不能大于{X}個(gè)月}
*/
compareEndTimeGTStartTime : function(month, startTime, endTime) {
var sms = new Date(startTime.replace(/-/g, "/"));
var ems = new Date(endTime.replace(/-/g, "/"));
var tDayms = month * 30 * 24 * 60 * 60 * 1000;
var dvalue = ems - sms;
if (dvalue > tDayms) {
return false;
}
return true;
},
/**
* 獲取最近幾天[開始時(shí)間和結(jié)束時(shí)間值,時(shí)間往前推算]
*/
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;
},
/**
* 獲取今天[開始時(shí)間和結(jié)束時(shí)間值]
*/
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;
},
/**
* 獲取明天[開始時(shí)間和結(jié)束時(shí)間值]
*/
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;
}
};

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 孟连| 天柱县| 奉节县| 垫江县| 通州区| 平武县| 桦南县| 宜宾县| 库伦旗| 宜川县| 克拉玛依市| 丁青县| 吴旗县| 三亚市| 白银市| 临江市| 青田县| 东莞市| 崇左市| 新龙县| 塘沽区| 永清县| 安福县| 南丰县| 宁陵县| 龙口市| 石狮市| 从江县| 卢湾区| 白玉县| 安达市| 延川县| 海林市| 彰化县| 抚宁县| 凤台县| 徐闻县| 巴林右旗| 普格县| 张家川| 中宁县|