Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Date in dd.MM.yyyy [duplicate]

Tags:

javascript

Possible Duplicate:
Javascript add leading zeroes to date

It might be a simple question because I am still newbie in JavaScript, assume I have DateTime in ISO format:

 2012-07-07T17:00:00

I would like to format this date to string:

 07.07.2012

I have written a function to format to 7.7.2012 as below:

var formatDate = function (datum) {
    var date = new Date(datum);
    return date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear();
};

How can I modify this code to get the result 07.07.2012 instead of 7.7.2012

like image 216
cuongle Avatar asked Sep 15 '25 00:09

cuongle


1 Answers

This might be helpful.

<script type="text/javascript">

    var date=new Date();
    day=date.getDate();
    month=date.getMonth();
    month=month+1;
    if((String(day)).length==1)
    day='0'+day;
    if((String(month)).length==1)
    month='0'+month;

    dateT=day+ '.' + month + '.' + date.getFullYear();
    //dateT=String(dateT);
    alert(dateT);
</script>
like image 85
polin Avatar answered Sep 17 '25 14:09

polin