Saturday, October 10, 2009

Date is joined inside the page with JavaScript

A lot of netizens should be met when the webpage that browse the function that discovers a lot of webpages have indication time and date, this is not difficult, use visible webpage to make software Dreameaver can insert time and date directly. But we use JavaScript to realize this function today, can rise to know the effect of JavaScript of network programming language at the same time, this example principle adopts JavaScript program namely carry out the date that makes individual client carries a machine and time to show on the webpage.

Its source program is as follows:



In this exemple, we are indispensible build variable of a date above all, this can be finished by Today= New Date() . If do not have special if appointing time and date, the browser will use this locality client to carry the time of the machine. If put it into variable Today, what the attention wants here is, we do not have declare Today of this variable model voice.

Outside dividing above function, you are OK also when building date thing beforehand set date is as follows:
DocStarted= New Date(96, 0, 13)

It is above all year, it is a month then (but remember decreasing 1) , it is day then again. Same method als o can impose the set of time. Following DocStarted = New Date(96, 0, 13, 10, 50, before 0) 3 are date year, month, day, it is then when, cent, second.

Finally, we must remind you JavaScript does not have effective date condition, but it however can ground of without striking a blowing shows date and time, the reason is it it is from   of 1 / 1/ 1970 0 0h begins to be calculated with Ms(milli Seconds) of current time, this sounds it seems that some are complex. But you need not worry, what it has a level is common function can be calculated, it you should know how to be used only is OK that you should know how to be used only.

No comments:

Post a Comment