js 如何获得今天前两天时间

js 如何获得今天前两天时间,第1张

//---------------------------------------------------

// 将指定的number值添加到日期

// interval:s(秒)m(分)h(小时)d(天)w(周) q(季度) M(月)y (年)

// number:数值

//---------------------------------------------------

DateprototypeAdd = function(interval, number) {

switch (interval) {

case 's': return new Date(Dateparse(this) + (1000 number));

case 'm': return new Date(Dateparse(this) + (60000 number));

case 'h': return new Date(Dateparse(this) + (3600000 number));

case 'd': return new Date(Dateparse(this) + (86400000 number));

case 'w': return new Date(Dateparse(this) + ((86400000 7) number));

case 'M': return new Date(thisgetFullYear(), (thisgetMonth()) + number, thisgetDate());

case 'q': return new Date(thisgetFullYear(), (thisgetMonth()) + number 3, thisgetDate());

case 'y': return new Date((thisgetFullYear() + number), thisgetMonth(), thisgetDate());

}

}

DateprototypeAddSecond = function(number) { return thisAdd("s", number); }

DateprototypeAddMinute = function(number) { return thisAdd("m", number); }

DateprototypeAddHour = function(number) { return thisAdd("h", number); }

DateprototypeAddDay = function(number) { return thisAdd("d", number); }

DateprototypeAddWeek = function(number) { return thisAdd("w", number); }

DateprototypeAddMonth = function(number) { return thisAdd("M", number); }

DateprototypeAddQuarter = function(number) { return thisAdd("q", number); }

DateprototypeAddYear = function(number) { return thisAdd("y", number); }

Date对象的扩展。

前两天 好像是: new Date()AddDay(-2)

这些都是简单js脚本问题 问题1:today后头这个小数点是脚本对象调用函数或者属性时必写的元素 问题2:thisDay = todaygetDate() today已经在上面定义 后面的就是所谓的脚本函数了 是日期对象特有的函数问题3:这个就是当上面定义的timerRunning为真时 设置timerRunning为假 让时间停止而已

其实我是来混经验的

////////////////////////////////////////////////////////////////////////////////////////////////////

//获取当前日期在当前年第几周函数封装,例如2014-01-10 是当前年的第2周

////////////////////////////////////////////////////////////////////////////////////////////////////

function theWeek() {

var totalDays = 0;

now = new Date();

years = nowgetYear()

if (years < 1000)

years += 1900

var days = new Array(12);

days[0] = 31;

days[2] = 31;

days[3] = 30;

days[4] = 31;

days[5] = 30;

days[6] = 31;

days[7] = 31;

days[8] = 30;

days[9] = 31;

days[10] = 30;

days[11] = 31;

//判断是否为闰年,针对2月的天数进行计算

if (Mathround(nowgetYear() / 4) == nowgetYear() / 4) {

days[1] = 29

} else {

days[1] = 28

}

if (nowgetMonth() == 0) {

totalDays = totalDays + nowgetDate();

} else {

var curMonth = nowgetMonth();

for (var count = 1; count <= curMonth; count++) {

totalDays = totalDays + days[count - 1];

}

totalDays = totalDays + nowgetDate();

}

//得到第几周

var week = Mathround(totalDays / 7);

return week;

}

下面是获取当月的第几周

<script language="javascript">var getMonthWeek = function (a, b, c) { / a = d = 当前日期 b = 6 - w = 当前周的还有几天过完(不算今天) a + b 的和在除以7 就是当天是当前月份的第几周 / var date = new Date(a, parseInt(b) - 1, c), w = dategetDay(), d = dategetDate(); return Mathceil( (d + 6 - w) / 7 ); };

var getYearWeek = function (a, b, c) { / date1是当前日期 date2是当年第一天 d是当前日期是今年第多少天 用d + 当前年的第一天的周差距的和在除以7就是本年第几周 / var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1), d = Mathround((date1valueOf() - date2valueOf()) / 86400000); return Mathceil( (d + ((date2getDay() + 1) - 1)) / 7 ); }; today=new Date();//获取当前时间var y = todaygetYear();var m = todaygetMonth()+1;var d = todaygetDate();documentwrite( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周" ); </script>

你好,

两个时间戳比较简单,new两个当前date对象,将时、分,分别设置为零点和23:59分,再gettime就可以了。只接代码:

var zero = new date();

var eleven = new date();

zerosethours(0);

zerosetminutes(0);

zerosetseconds(0);

elevensethours(23);

elevensetminutes(59);

elevensetseconds(0);

consolelog('今天零点:' + zerogettime());

consolelog('23:59:' + elevengettime());希望解决了你的问题,如有疑问可追问!

以上就是关于js 如何获得今天前两天时间全部的内容,包括:js 如何获得今天前两天时间、thisDay = today.getDate();、js获取当前日期第几周等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9567415.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存