一个月的一天 [英] day of month

查看:60
本文介绍了一个月的一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中列出了在一周特定的

天内发生的会议地点(会议在兰利的第1和第3个星期四举行 -

一个例子)


以下代码适用于星期几,但是当我列出明天会议时,我有一个

问题这个星期是

一周的最后一天 - 它不会认出下一个飞蛾的第一天是

tomorrows date。

我知道这可能非常粗糙,但这就是我一直在使用的 - 任何

的想法???


< script language =" JavaScript">

<! -

明天函数(){


var mydate = new日期()

var day = mydate.getDay()

var daym = mydate.getDate()

if(daym< 10)

daym =" 0" + daym

var tom = day + 1

var daymtom = daym + 1

var week1array = new Array(No Meeting&q uot;,Surrey,Cloverdale,No

Meeting,Langley,No Meeting,No Meeting)

var week2array = new Array(No Meeting,No

Meeting"," Whiterock,Abbotsford,Hope,No Meeting," ;没有会议")

if((daymtom)< 8)

{document.write("< small>< font

face =''Arial''>< b>" + week1array [tom] +"< / b>< / font>< / small>")}

else if((daymtom)< 15)

{document.write("< small>< font

face =''Arial''> ;< b>" + week2array [tom] +"< / b>< / font>< / small>")}

else if((daymtom)< 22)

{document.write("< small>< font

face =''Arial''>< b>" + week1array [ tom] +"< / b>< / font>< / small>")}

else i f((daymtom)< 29)

{document.write("< small>< font

face =''Arial''>< b>" + week2array [tom] +"< / b>< / font>< / small>")}

else

{document .write(No Meeting)}

}

// - >

< / script>

解决方案

先知写道:

我有一个页面列出了一周中特定
天的会议地点(每个第1和第3个星期四的会议都在兰利 - 作为一个例子)

以下代码适用于何时它是星期几,但我有一个
当我列出明天会议时的问题,今天的日期是本周的最后一天 - 它将无法识别下一个飞蛾的第一天是否明天约会。


那是因为你得到今天的日期,然后如果你的价格低于10,那么你需要将b兑换成一个字符串,否则你保持它作为一个数字。


我知道这可能非常粗糙,但这就是我一直在使用的 - 任何
想法???
< script language =" JavaScript">


不推荐使用language属性,类型是必需的:


< script type =" text / javascript">


<! -


脚本元素内的HTML注释分隔符没有用处

并且可能有害 - 只是不要用它们。


明天功能(){

var mydate = new Date()
var day = mydate.getDay( )
var daym = mydate.getDate()
if(daym< 10)
daym =" 0" + daym
var tom = day + 1


如果汤姆应该是明天的天数:


var tom =(day + 1)%7;


var daymtom = daym + 1


如果daymtom应该是明天的日期:


mydate.setDate(mydate.getDate( )+ 1);

var daymtom = mydate.getDate();

mydate现在已经设置为明天,但你不再使用它了所以/>
应该没问题。

你可能想用fu添加前导零点:


函数addZ(n)

{

return(x< 10)? ''0''+ x:''''+ x;

}


确保n总是以字符串形式返回(如果是'你想要什么)。

现在行:

var daym = mydate.getDate()

成为:

var daym = addZ(mydate.getDate());

和以下''if''语句是多余的。

var week1array = new Array (No Meeting,Surrey,Cloverdale,No
Meeting,Langley,No Meeting,No Meeting)


您可能会发现维护更容易初始化数组:

var week1array = [

No Meeting,

Surrey,

Cloverdale,

No Meeting,

Langley,

没有会议,

没有会议

]

也许它已经生成了代码所以没关系...


va r week2array = new Array(No Meeting,No
Meeting,Whiterock,Abbotsford,Hope,No Meeting,No Meeting)

if((daymtom)< 8)
{document.write("< small>< font
face =''Arial''>< b> ;" + week1array [tom] +"< / b>< / font>< / small>")}
if if((daymtom)< 15)
{document .write("< small>< font
face =''Arial''>< b>" + week2array [tom] +"< / b>< / font>< ; / small>")}
if if((daymtom)< 22)
{document.write("< small>< font
face =''Arial' '>< b>" + week1array [tom] +"< / b>< / font>< / small>")}
if if((daymtom)< 29)
{document.write("< small>< font
face =''Arial''>< b>" + week2array [tom] +"< / b> < / font>< / small>")}
else
{document.write(" No Meeting")}


会议从未在29日,30日或31日召开?


}




有多种规则可以确定你/ b
的月哪个星期,确保用户了解你的算法是什么正在使用。

在我看来你的周数由下式给出:


var weekNum = Math.floor((daymtom-1)/ 7)+ 1 ;

你对28岁以上的日期做了什么?

[...]

-

Rob




RobG写道:

[snip]

你可能想用添加前导零的函数:

函数addZ(n)
返回(x <10)? ''0''+ x:''''+ x;
}
确保n总是以字符串形式返回(如果这是你想要的)。



函数addZ(n)

{

return(n< 10)? ''0''+ n:''''+ n;

}


Jambalaya写道:

函数addZ(n)
{
返回(n< 10)? ''0''+ n:''''+ n;
}




压缩,娱乐:


函数addZ(n){return(n< 10&&''0'')+ n}


-

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


I have a page which lists of locations of meetings that occur on specific
days of the week (every 1st and 3rd Thursday the meeting is in Langley - as
an example)

The following code works for when it is the day of the week, but I have a
problem when I list tomorrows meeting and today''s date is the last day of
the week - it will not recognise the 1st day of the next moth as being
tomorrows date.

I know this is probably very crude, but this is what I have been using - any
ideas???

<script language="JavaScript">
<!--
function tomorrow() {

var mydate=new Date()
var day=mydate.getDay()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var tom=day+1
var daymtom=daym+1

var week1array=new Array("No Meeting","Surrey","Cloverdale","No
Meeting","Langley","No Meeting","No Meeting")
var week2array=new Array("No Meeting","No
Meeting","Whiterock","Abbotsford","Hope","No Meeting","No Meeting")
if ((daymtom)<8)
{document.write("<small><font
face=''Arial''><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<15)
{document.write("<small><font
face=''Arial''><b>"+week2array[tom]+"</b></font></small>")}
else if ((daymtom)<22)
{document.write("<small><font
face=''Arial''><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<29)
{document.write("<small><font
face=''Arial''><b>"+week2array[tom]+"</b></font></small>")}
else
{document.write("No Meeting")}
}
// -->
</script>

解决方案

Prophet wrote:

I have a page which lists of locations of meetings that occur on specific
days of the week (every 1st and 3rd Thursday the meeting is in Langley - as
an example)

The following code works for when it is the day of the week, but I have a
problem when I list tomorrows meeting and today''s date is the last day of
the week - it will not recognise the 1st day of the next moth as being
tomorrows date.
That is because you get today''s date, then if it''s less than 10 you
convert it to a a string, otherwise you keep it as a number.


I know this is probably very crude, but this is what I have been using - any
ideas???

<script language="JavaScript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

<!--
HTML comment delimiters inside script elements serve no useful purpose
and are potentially harmful - just don''t use them.

function tomorrow() {

var mydate=new Date()
var day=mydate.getDay()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var tom=day+1
If tom should be the day number for tomorrow:

var tom = (day + 1)%7;

var daymtom=daym+1
If daymtom should be tomorrow''s date:

mydate.setDate(mydate.getDate() + 1);
var daymtom = mydate.getDate();
mydate has now been set to tomorrow, but you don''t use it anymore so
it should be OK.
You may want to use a function to add the leading zero:

function addZ(n)
{
return (x<10)? ''0''+x : ''''+x;
}

Ensures n is always returned as a string (if that''s what you want).
Now the line:
var daym=mydate.getDate()
becomes:

var daym = addZ(mydate.getDate());
and the following ''if'' statement is redundant.

var week1array=new Array("No Meeting","Surrey","Cloverdale","No
Meeting","Langley","No Meeting","No Meeting")
You may find it easier for maintenance to initialise arrays:

var week1array = [
"No Meeting",
"Surrey",
"Cloverdale",
"No Meeting",
"Langley",
"No Meeting",
"No Meeting"
]
Maybe it''s generated code so it doesn''t matter...

var week2array=new Array("No Meeting","No
Meeting","Whiterock","Abbotsford","Hope","No Meeting","No Meeting")
if ((daymtom)<8)
{document.write("<small><font
face=''Arial''><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<15)
{document.write("<small><font
face=''Arial''><b>"+week2array[tom]+"</b></font></small>")}
else if ((daymtom)<22)
{document.write("<small><font
face=''Arial''><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<29)
{document.write("<small><font
face=''Arial''><b>"+week2array[tom]+"</b></font></small>")}
else
{document.write("No Meeting")}
Are meetings never held on the 29th, 30th or 31st?

}



There are a variety of rules to determine which week of the month you
are in, make sure users understand what algorithm you are using.
Seems to me your week number is given by:

var weekNum = Math.floor((daymtom-1)/7) + 1;
What do you do for dates beyond 28?
[...]
--
Rob



RobG wrote:
[snip]

You may want to use a function to add the leading zero:

function addZ(n)
{
return (x<10)? ''0''+x : ''''+x;
}

Ensures n is always returned as a string (if that''s what you want).



function addZ(n)
{
return (n<10) ? ''0''+n : ''''+n;
}


Jambalaya wrote:

function addZ(n)
{
return (n<10) ? ''0''+n : ''''+n;
}



compacting, for amusement:

function addZ(n){return (n<10&&''0'')+n}

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


这篇关于一个月的一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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