JavaScript Date and Time

Javascript has a lot of inbuilt methods you can use to get the date and time. The first thing you need to do is to create a new Date object:

var d = new Date();

Example to get the current date:


var d = new Date();


var d1=d.getDay();

var m=d.getMonth()+1;

var y=d.getFullYear();

document.write(“Today is “ + d1 + “/” +m + “/” +y);


Example – Age Calculator



Function age() {

Var byear =prompt(“enter Year of Birth ?”);

var d = new Date();

var y=d.getFullYear();

var q=y-byear;

alert(“You are  “+q + “ Years Old”);

}  </script>



<h2>Age Calculator Example </h2>

<input type=”button” value=”Calculate Age” onclick=”age()”>



Week Days Example – Switch Case


function viewday()


var d=new Date().getDay();



case 0:



case 1:



case 2:



case 3:



case 4:



case 5:









<input type=”button” value=”Get Day” onclick=” viewday()”>

12 thoughts on “JavaScript Date and Time

  1. I actually wanted to write down a comment in order to thank you for the awesome points you are posting at this website. My particularly long internet lookup has at the end of the day been recognized with useful strategies to talk about with my great friends. I ‘d suppose that we visitors actually are very blessed to live in a notable network with many marvellous people with beneficial methods. I feel rather fortunate to have discovered your entire web site and look forward to tons of more fabulous times reading here. Thank you once again for a lot of things.

  2. I would like to point out my love for your generosity in support of folks who should have help with this area of interest. Your personal commitment to passing the message all through appears to be exceedingly insightful and has specifically allowed women like me to realize their pursuits. Your new insightful guidelines entails a great deal a person like me and additionally to my mates. Many thanks; from each one of us.

  3. I want to show my affection for your generosity for those who really need guidance on this important issue. Your special dedication to getting the solution all-around appeared to be extremely significant and has truly permitted men and women like me to realize their goals. Your personal valuable guidelines indicates a lot a person like me and further more to my peers. Many thanks; from each one of us.

  4. An attention-grabbing dialogue is worth comment. I feel that you should write more on this subject, it might not be a taboo topic but typically people are not sufficient to talk on such topics. To the next. Cheers

  5. I wanted to write you that bit of note to be able to thank you again with your wonderful views you have provided in this article. This is quite tremendously generous of people like you to provide unhampered what exactly many people would’ve offered as an electronic book to earn some money for themselves, even more so seeing that you might well have tried it in the event you decided. These tricks likewise worked like the good way to understand that some people have the same eagerness really like my own to figure out a whole lot more concerning this issue. I am sure there are thousands of more pleasurable periods ahead for many who read through your website.

  6. Others is capable of a harder erection but cannot maintain it during sexual intercourse. Thus, when the muscles inside the penile area are relaxed, more blood will type in the penis and a bigger harder erection will occur.

  7. I intended to send you a very little remark to thank you very much yet again for all the nice ideas you’ve contributed on this page. It was unbelievably open-handed with you to offer without restraint just what a lot of folks might have sold for an e book to end up making some profit on their own, and in particular seeing that you might have tried it if you ever wanted. The advice in addition acted to become a fantastic way to recognize that some people have the same dreams similar to mine to find out much more when it comes to this problem. I know there are millions of more enjoyable situations ahead for those who look into your site.

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email