- var cDate = new Date ([parameter | parameters]);
The result is the cDate date object. If the function is called without parameters, it returns the current date object as a result.
A numeric parameter is allowed (only when it is one), which is interpreted as the number of milliseconds elapsed since 01/01/1970 (00:00:00 GMT).
You can use strings and numbers as parameters. For example, "21 January 1965" or "13 May 2002". Both options work, although one is up to the point when the Unix era began.
If you specify the desired date exactly: "year, month, [date, [hour, [minutes, [seconds]]]], milliseconds, then in this case from two to seven digits are passed to the function constructor.For example, '2013,10,28,13,47,12,18' - here quotes are to indicate the list of parameters: the object of the date will be November 28, 2013, time 13: 47: 12.18.
You should carefully record the sequence of numbers and do not forget that January is 0, and December is 11. It is also important to remember that one number as a parameter is time in milliseconds, and two numbers or more are date numbers.
Very useful language feature. As parameters, 'f | k' is a function or code, and as 'and' is the value through which the function or code specified by the first parameter will be executed.
The interval value is set on the basis that 1000 is 1 second.
Numeric time equivalent
The date object has a time method, which is written as:
For example, executing the getTime () method on the cDate object will assign the iTime variable a numeric time value in milliseconds:
- var iTime = cDate.getTime ().
The time value is counted in both directions from the beginning of the "Unix" era: 1.1.1970.
Date object methods
Methods for getting the year (getFullYear), month (Month), day (Date), hour (Hours). The names of the methods correspond to English words, and their use is not difficult.
- date / time on site pages;
- periodic processes of the site pages;
- information exchange through AJAX with the server.
Date, time and periodic page processes
The simplest application, in addition to the traditional output of the current time on the page, is very originally to wish for "good morning", "good day". Although this feature is not enough for anyone, it is not worth forgetting about it.
The time spent on the page does matter. At the same time, the time of leaving the page can be traced by means of the above timer with the required accuracy. This element is important for applications that are in continuous dialogue with the client, for example for:
- instant message delivery;
- billing for immediate work;
- tracking staff time and similar procedures.
Exchange with server: AJAX
The most direct and accessible that is required from the date object and timer is the tracking of external events. A simple example: the exchange. Tables, quotes, various data are continuously updated.If the site participates in the auction, it must periodically, according to the rules established by the exchange, collect the necessary information.
To perform all marked and similar works, the timer is a rather complex structure. It may not always be a single algorithm and must not always work with constant tact. The specifics of the problem may impose a lot of restrictions and conditions.
In modern site building it is important to completely different.The date and time should be presented in the context of the task, the processes that surround it, and the specifics of the application. It is also important to take into account the temporary characteristics of the server, client computer and communication lines. Programming is already out of the age when syntax ruled over semantics.
Time essentially changed everything, the syntax can now allow even semantics outside its constructions. If the world is represented by objects, using arrays and stack ideas, then objects of date and time will acquire a different meaning.