How can I format this date?
<li>Sat Mar 03 2012 14:16:05 GMT+0530 (India Standard Time)</li>
I used new date() function to get date in this li. I want date like this 03/03/2012
How can I format this date?
<li>Sat Mar 03 2012 14:16:05 GMT+0530 (India Standard Time)</li>
I used new date() function to get date in this li. I want date like this 03/03/2012
function dateFormat(){
var d = new Date();
date = d.getDate();
date = date < 10 ? "0"+date : date;
mon = d.getMonth()+1;
mon = mon < 10 ? "0"+mon : mon;
year = d.getFullYear()
return (date+"/"+mon+"/"+year);
}
dateFormat();
All you need to do is tell the date function to format the date to the kind of output you want.
(Assuming you are using date function of JavaScript, which you did mention above.)
http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3
<script type="text/javascript">
<!--
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(curr_date + "-" + curr_month + "-" + curr_year);
//-->
</script>
OR
http://blog.stevenlevithan.com/archives/date-time-format
OR
http://archive.plugins.jquery.com/project/jquery-dateFormat
<script>
$.format.date("2009-12-18 10:54:50.546", "dd/MM/yyyy");
</script>