更新时间:2023-01-31 17:44:37
我写了一个有用的。
函数nextFriday()
{
var d = new Date();
开关(d.getDay())
{
案例0:d.setDate(d.getDate()+ 5);
休息;
案例1:d.setDate(d.getDate()+ 4);
break;
案例2:d.setDate(d.getDate()+ 3);
休息;
案例3 :d.setDate(d.getDate()+ 2);
break;
case 4:d.setDate(d.getDate()+ 1 );
休息;
案例6:d.setDate(d.getDate()+ 6);
break;
}
返回d;
}
" ; CK" c为C _ ********** @ hotmail.com>在消息中写道
news:9x ****************** @ newssvr21.news.prodigy.c om ...
I wrote one that works.
function nextFriday()
{
var d = new Date();
switch (d.getDay())
{
case 0: d.setDate(d.getDate() + 5);
break;
case 1: d.setDate(d.getDate() + 4);
break;
case 2: d.setDate(d.getDate() + 3);
break;
case 3: d.setDate(d.getDate() + 2);
break;
case 4: d.setDate(d.getDate() + 1);
break;
case 6: d.setDate(d.getDate() + 6);
break;
}
return d;
}
"CK" <c_**********@hotmail.com> wrote in message
news:9x******************@newssvr21.news.prodigy.c om...
寻找一个简单的功能来返回星期五的日期。
我不时发送电子邮件,我想要一个动态返回日期的功能为了星期五。所以无论我发送的是什么,它都会动态计算星期五的日期。此外,如果我在星期五发送它,我想返回当前日期,星期六
以后将返回下周五的日期。感谢您的任何建议。
亲切的问候,
CK
Hi All,
Looking for a simple function to return the date for the follwing Friday.
I send out emails from time to time and I would like a function that
dynamically returns the date for the follwing Friday. So no matter what
day I send it, it will dynamically calculate Friday''s date. Also if I am
sending it on a Friday, I would like to return the current date, Saturday
and later will return next Friday''s date. Thanks for any advice.
Kind Regards,
CK
CK写道:
我发送它,它将动态计算星期五的日期。另外,如果我在星期五发送
它,我想返回当前日期,星期六和之后
将在下周五的日期返回。感谢您的任何建议。
I send it, it will dynamically calculate Friday''s date. Also if I am sending
it on a Friday, I would like to return the current date, Saturday and later
will return next Friday''s date. Thanks for any advice.
函数nextDay(day){
var d =新日期;
( day =(Math.abs(+ day || 0)%7) - d.getDay())< 0&& (日+ = 7);
返回日&& d.setDate(d.getDate()+ day),d;
};
day参数的范围是0到6.
-
Jonas Raoni Soares Silva
http: //www.jsfromhell.com
Lee写道:
CK说:
CK said:
寻找一个简单的功能来返回星期五的日期。我不时发送电子邮件,我想要一个能够动态返回星期五的日期的功能。所以不管我发送它的那一天,它都会动态计算星期五的日期。另外,如果我在星期五发送
它,我想返回当前日期,星期六和之后
将在下周五的日期返回。感谢您的任何建议。
Hi All,
Looking for a simple function to return the date for the follwing Friday. I
send out emails from time to time and I would like a function that
dynamically returns the date for the follwing Friday. So no matter what day
I send it, it will dynamically calculate Friday''s date. Also if I am sending
it on a Friday, I would like to return the current date, Saturday and later
will return next Friday''s date. Thanks for any advice.
var d = new Date();
d.setDate(d.getDate()+(12-d.getDay())%7 );
d现在是当前日期,如果它是星期五或下个星期五的日期。
var d=new Date();
d.setDate(d.getDate()+(12-d.getDay())%7);
d is now the current date if it is Friday or the date of the next Friday.
噢,到底是什么,这是'基于for循环的另一个:
for(var x = new Date(); x.getDay()!= 5; x.setDate(x.getDate( ))))}} {}
alert(''下周五是'''+ x.getDate());
-
Rob
Aw, what the heck, here''s another based on a for loop:
for (var x=new Date(); x.getDay()!=5; x.setDate(x.getDate()+1)){}
alert(''Next Friday is ... '' + x.getDate());
--
Rob