给定一个日期如何获得星期天&那一周的星期六 [英] Given a date how to get Sunday & Saturday of that week

查看:152
本文介绍了给定一个日期如何获得星期天&那一周的星期六的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到星期天和星期天。提供日期的星期六。
我只能访问以下函数:

I want to get the Sunday & Saturday of the week from which a date is provided. I have access to the following functions only:


  • getDate()返回0-6(0是星期日)的数字

  • getDay()返回1-31的数字

  • getMonth()返回0-11之间的数字

  • getFullYear )返回当前年度

  • getDate() returns a number from 0-6 (0 being sunday)
  • getDay() returns a number from 1-31
  • getMonth() returns a number from 0-11
  • getFullYear() returns the current year

我在钛矿做这个。

推荐答案

根据上面的描述,我想出了:

Per your description above, I came up with:

var sat = new Date(input.getFullYear(), input.getMonth(), 6 - input.getDate() + getDay());
var sun = new Date(input.getFullYear(), input.getMonth(), getDay() + (input.getDate() - 6));

如果我按照MDN文档,我想出了(在Ti中也有效):

If I follow the MDN doc, I come up with (works in Ti too):

var sat = new Date(input.getFullYear(), input.getMonth(), 6 - input.getDay() + input.getDate());
var sun = new Date(input.getFullYear(), input.getMonth(), input.getDate() + (input.getDay() - 6));

其中输入是JavaScript Date对象。

Where input is a javascript Date object.

如果需要,日期对象会照顾或更改月份和/或年份。

The date object will take care or changing the month and/or year if necessary.

希望这有助于。

这篇关于给定一个日期如何获得星期天&那一周的星期六的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆