Search Your Project Here Please

Define object oriented programming in JavaScript? How to create a data object in java script ? how to compose two dates in JavaScript?


Define object oriented programming in JavaScript? How  to create a data object in java script ? how to compose two dates in JavaScript?

Ans:object oriented programming in JavaScript :

JavaScript is an excellent language to write object oriented web applications. It can support OOP because it supports inheritance through prototyping as well as properties and methods. Many developers cast off JS as a suitable OOP language because they are so used to the class style of C# and Java.

Create a Date Object:

The Date object is used to work with dates and times. 
Date objects are created with the Date() constructor.
There are four ways of initiating a date:
new Date() // current date and time
new Date(milliseconds) //milliseconds since 1970/01/01
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)

Compare Two Dates:

The Date object is also used to compare two dates.
The following example compares today's date with the 14th January 2100:
var x=new Date();
x.setFullYear(2100,0,14);
var today = new Date();

if (x>today)
  {
  alert("Today is before 14th January 2100");
  }
else
  {
  alert("Today is after 14th January 2100");
  }

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...