21-09-2016, 10:40 AM
1455522739-stexp3.docx (Size: 91.17 KB / Downloads: 7)
a. Write a JavaScript code for implementing Date object, Math object, Array object, Document object and Event object.
Theory
1. Explain javascript object
2. Explain how to create and use user defined object.
3. Explain how to define object function and use it.
Date Object
The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ) as shown below.
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
The ECMAScript standard requires the Date object to be able to represent any date and time, to millisecond precision, within 100 million days before or after 1/1/1970. This is a range of plus or minus 273,785 years, so the JavaScript is able to represent date and time till year 275755.
Syntax:
Here are different variant of Date() constructor:
new Date( )
new Date(milliseconds)
new Date(datestring)
new Date(year,month,date[,hour,minute,second,millisecond ])
Note: Paramters in the brackets are always optional
Here is the description of the parameters:
• No Argument: With no arguments, the Date( ) constructor creates a Date object set to the current date and time.
• milliseconds: When one numeric argument is passed, it is taken as the internal numeric representation of the date in milliseconds, as returned by the getTime( ) method. For example, passing the argument 5000 creates a date that represents five seconds past midnight on 1/1/70.
• datestring:When one string argument is passed, it is a string representation of a date, in the format accepted by the Date.parse( ) method.
• 7 agruments: To use the last form of constructor given above, Here is the description of each argument:
1. year: Integer value representing the year. For compatibility (in order to avoid the Y2K problem), you should always specify the year in full; use 1998, rather than 98.
2. month: Integer value representing the month, beginning with 0 for January to 11 for December.
3. date: Integer value representing the day of the month.
4. hour: Integer value representing the hour of the day (24-hour scale).
5. minute: Integer value representing the minute segment of a time reading.
6. second: Integer value representing the second segment of a time reading.
7. millisecond: Integer value representing the millisecond segment of a time reading.