重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章将为大家详细讲解有关JS中如何处理时间,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
罗定ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
在项目中用到的,用js 来得到年月日,星期,当前多少个周的函数,备忘在这里,以后参考。
Date.prototype.getWeek = function(){ var firstDayOfYear = new Date(this.getFullYear(),0,1); var millOfDay = 24*60*60*1000; return Math.ceil((((this - firstDayOfYear) / millOfDay) + firstDayOfYear.getDay()+1)/7); }; /* 01 October 2013-10:20:20 01 November 2013-10:20:20 01 December 2013-10:20:20 08 October 2013-01:55 pm */ var monthMapping = { "January" : "01", "February" : "02", "March" : "03", "April" : "04", "May" : "05", "June" : "06", "July" : "07", "August" : "08", "September" : "09", "October" : "10", "November" : "11", "December" : "12" }; function formatAmPm() { var dateTimeStr = arguments[0] ; var dateStr = dateTimeStr.split("-"); if (lang.currentLang == "zh_CN" || lang.currentLang == "zh_TW"){ var s_year = lang.getMessage('yearCn') ; var s_month = lang.getMessage('monthCn') ; var s_day = lang.getMessage('dayCn') ; var dateArray = dateStr[0].split(" ") ; var s_time = dateStr[1].split(" ")[1] == "am" ? lang.getMessage('amCn') :lang.getMessage('pmCn') ; var ret = dateArray[2] + s_year + monthMapping[dateArray[1]] + s_month + dateArray[0] + s_day + " " + s_time + dateStr[1].split(" ")[0] ; if ( arguments.length > 1 ){ /*admin feature ,so using en date*/ ret = arguments[1] ? dateStr[0] : dateStr[1] ; } return ret ; } else{ if ( arguments.length > 1 ){ return arguments[1] ? dateStr[0] : dateStr[1] ; } else{ return dateStr[0] + " " + dateStr[1] ; } } } function formatDate(dateTime, pattern) { if(pattern == "" || pattern == null) { pattern = "/"; } var date = new Date(dateTime); var year = date.getFullYear(); var month = date.getMonth()+1; month = month <10 ? '0'+month : month; var day = date.getDate(); day = day <10 ? '0'+day : day; return month + pattern + day + pattern + year; } function formatDateDDMMYYYY(dateTime) { var ymd = dateTime.split(" ")[0]; var dateArray = ymd.split("-"); return dateArray[2]+"."+dateArray[1]+"."+dateArray[0]; } /** * * @param dateTime YYYY-MM-DD hh:mm:ss */ function formatDateDDMMYY(dateTime){ var ymd = dateTime.split(" ")[0]; var dateArray = ymd.split("-"); return dateArray[2]+"."+dateArray[1]+"."+dateArray[0].substring(2); } /**********************calculate date*****************************/ var MONTH = [ {key:"Jan.",value:1}, {key:"Feb.",value:2}, {key:"Mar.",value:3}, {key:"Apr.",value:4}, {key:"May.",value:5}, {key:"Jun.",value:6}, {key:"Jul.",value:7}, {key:"Aug.",value:8}, {key:"Sept.",value:9}, {key:"Oct.",value:10}, {key:"Nov.",value:11}, {key:"Dec.",value:12} ]; var DAYS = [31,28,31,30,31,30,31,31,30,31,30,31]; function getYears(){ var years = []; var date = new Date(); var year = date.getFullYear(); var minYear = year - 10; for(var currentYear=minYear;currentYear <= year;currentYear++){ years.push(currentYear); } return years; }; function fillinMonthOptions(id,currentMonth){ $("#" + id).get(0).options.length = 0; for(var i= 0;i"+MONTH[i].key+""); } else{ $("#" + id).append(""); } } }; function fillinAllMonthOptions(monthIds,currentMonth){ //var monthIds = ["loginMonth_1","loginMonth_2","auditMonth_1","auditMonth_2"]; for (var i=0;i "+years[i]+""); } else{ $("#" + id).append(""); } } }; function fillinAllYearOptions(yearIds,currentYear){ //var yearIds = ["loginYear","auditYear"]; years = getYears(); for(var i= 0;i "+i+""); } } function fiilinDays(year,month,dayIds){ var monthDays = getMonthDays(year,month); for(var i=0;i "+week[0] + "(" + week[1]+"-"+week[2]+")"); } } function fillinWeeks(year,weekIds){ for (var i=0;i 关于“JS中如何处理时间”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
网页标题:JS中如何处理时间
标题链接:http://cqcxhl.com/article/gojhoh.html