Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am giving the endDate 2014-07-27 12:00 AM to following code it its generating Jul 28 2014 00:00:00 GMT+0530 (India Standard Time) but i want to display endDate like 2014-07-28 12:00 AM.How can i do it?

Code:
XML
endDate = "2014-07-27 12:00";
           alert(endDate);
           if (endTime == "12:00 AM") {
               endDate = new Date(endDate);
               // add a day
               endDate.setDate(endDate.getDate() + 1);
           }
Posted
Updated 25-Aug-14 20:18pm
v3

JavaScript
Number.prototype.padLeft = function(base,chr){
   var  len = (String(base || 10).length - String(this).length)+1;
   return len > 0? new Array(len).join(chr || '0')+this : this;
}
    

$('#showit').click(function(){
    var d = new Date,
        dformat = [ (d.getMonth()+1).padLeft(),
                    d.getDate().padLeft(),
                    d.getFullYear()].join('-')+
                    ' ' +
                  [ d.getHours().padLeft(),
                    d.getMinutes().padLeft(),
                    d.getSeconds().padLeft()].join(':');
     $('#result').html(dformat);
});


See this Example Done on JS Fiddle

http://jsfiddle.net/mthdA/404/[^]

Plz mark as answered if you got a help

If you want AM/PM Use this additional function.

http://jsfiddle.net/mthdA/406/[^]
 
Share this answer
 
v3
Comments
Gihan Liyanage 15-Sep-14 6:20am    
Did you got a solution from my support, I can see you have not accepted any answer.If you are ok with this answer plz accept it. Then any user having same problem can identified it has solved the problem..
try this one, How to formate date?[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900