Date Object in Javascript
Submitted by GeePee on Friday, October 24, 2014 - 00:13.
Language
In this project, you will learn about date objects in javascript. The Date object is used to work with date and time. And this is the default functional key.
The following are the Date Objects method. We will work only with the date.
Returns the month from 0 to 11.
It will return the day of the month.
It returns the 4 digit year.
After the get word of the date object is always a capital letter or else it will not work.
Now, let's get the day of the week.
This will return the number from 0 which represents Sunday and 1 is Monday, so on. In order for us to get the name of the weekday, we have put them in an array.
Very simple javascript code.
Hope you learn from this.
- var date = new Date();
- var month = date.getMonth();
- var day = date.getDate();
- var year = date.getFullYear();
- var getday = date.getDay();
- var weekday = new Array(7);
- weekday[0] = "Sunday";
- weekday[1] = "Monday";
- weekday[2] = "Tuesday";
- weekday[3] = "Wednesday";
- weekday[4] = "Thursday";
- weekday[5] = "Friday";
- weekday[6] = "Saturday";
- var getday = weekday[date.getDay()];
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 39 views