Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Javascript Date and Time

Javascript Date and Time

You can get date object to get and set date and time. Date objects are created with the new Date( ) as shown below.


Syntax of Creating a Date object

var variableName = new Date();
var variableName = new Date(milliseconds);
var variableName = new Date(dateString);
var variableName = new Date(year, month, day, hours, minutes,
                              seconds, milliseconds);

Example of Date

var todaydate = new Date();
alert(todaydate);


Some General Date Methods

  • Date(): Returns today's date and time.

  • getDate(): Returns the day of the month for the specified date according to local time.

  • getDay(): Returns the day of the week for the specified date according to local time.

  • getFullYear(): Returns the year of the specified date according to local time.

  • getHours(): Returns the hour in the specified date according to local time.

  • getMilliseconds(): Returns the milliseconds in the specified date according to local time.

  • getMinutes(): Returns the minutes in the specified date according to local time.

  • getMonth(): Returns the month in the specified date according to local time.

  • getSeconds(): Returns the seconds in the specified date according to local time.

  • setDate(): Sets the day of the month for a specified date according to local time.

  • setHours(): Sets the hours for a specified date according to local time.

  • setMilliseconds(): Sets the milliseconds for a specified date according to local time.

  • setMinutes(): Sets the minutes for a specified date according to local time.

  • setMonth(): Sets the month for a specified date according to local time.

  • setSeconds(): Sets the seconds for a specified date according to local time.

PreviousNext

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH