How to get Current year with javascript
I want write a code where i can get the current year.I have asked about the same to my friends too they told me that it's possible with javascript but don't know what would be the code for the same.Anyone over here can provide me code for getting current year.
Re: Get Current year with javascript
Try to use the following code for getting Current year by using javascript
Code:
<script type="text/javascript">
<!--
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(curr_date + "-" + m_names[curr_month]
+ "-" + curr_year);
/* The last two lines above have
to placed on a single line */
//-->
</script>
Re: Print Current year with javascript
If you want to get current year following are the code for the same
Code:
<script type="text/javascript">
var brn = new Date("July 21, 2009 01:17:00");
document.write("I was born in " + brn.getYear());
var da = new Date();
document.write(da.getYear());
</script>