Date Format using javascript

Below is the code to change different format of date using a javascript. If you have a date in a string format, you can use the string functions of javascript to give any format you want.

I have a date format which is in m-d-yyyy format and I want to change it in dd-mm-yy format.



<script language="javascript" type="text/javascript">
$(document).ready(function()
var vArticledate=$("#datefield").text();
var dt = vArticledate.split("/");

var iMonth=dt[0];
if(iMonth.length<2)
  iMonth="0"+iMonth;

var iDay=dt[1];
if(iDay.length<2)
iDay="0"+iDay;

var iYear=dt[2];
iYear = iYear.substring(iYear.indexOf("0")+1,iYear.length);

document.getElementById('datefield').innerHTML = "<b>"+iDay +"-"+iMonth+"-"+iYear+" </b>";

}) 
</script>

No comments:

Post a Comment