<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="utf-8"> <title>js时间格式化函数,支持Unix时间戳</title> </head>…
//时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month "d+": this.getDate(), //day "h+": this.getHours(), //hour "m+": this.getMinutes(), //minute "s+": this.get…
var curTime = new Date(); //2把字符串格式转换为日期类 var startTime = new Date(Date.parse("2018-3-28 16:44")); var endTime = new Date(Date.parse("2018-3-28 16:45")); console.log(startTime) console.log(endTime ) //3进行比较 console.log(curTime >= st…
Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds()…
一.判断数据类型: 常见的判断有typeof.instanceof. constructor. prototype,先来看typeof: var a = "hello world"; var b = 10; var c = [1, 3, 5]; var d = new Date(); var e = function() {}; console.log(typeof a); // string console.log(typeof b); // number console.log(t…
字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" :…
Date 对象的方法简介: ·Date    | 返回当日的日期和时间 ·getDate | 从 Date 对象返回一个月中的某一天 (1 ~ 31) ·getDay | 从 Date 对象返回一周中的某一天 (0 ~ 6) ·getFullYear | 根据本地时间获取当前年份(四位数字) ·getHours | 根据本地时间获取当前小时数(24小时制,0-23) ·getMilliseconds | 根据本地时间获取当前毫秒数(0 ~ 999) ·getMinutes | 根据本地时间获取当…
1. 判断是否是闰年 function isLeapYear(eDate) { var year = eDate.getFullYear(); return (((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400)); } 2. 获取月份的总天数 function getDaysInMonth(eDate) { var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];…
* 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { let date; if (this.isString(dateObj)) { date = this.strToDate(dateObj) } else if (this.isDate(dateObj)) { date=dateObj } else{ return "" } var o =…
  var now = new Date(); let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();//2018-3-27 var nowDayOfWeek = now.getDay(); console.log(nowDayOfWeek ) dateObject.getDay()返回值dateObject 所指的星期中的某一天,使用本地时间.返回值是 0(周日) 到 6(周六) 之间的…