Time Problem in DateTime
Time Problem in DateTime
hey guys !
i'm facing a problem in my Time format in DateTime
i used render function for formatting the DateTime
it shows desired result when time is like 12:10 or 15:27 etc.
problem is when i've time in Database less than 10 minutes like 12:09 or 12:06. if time is less than 10 mnts then it shows me time like this 12:9 AM 12:6 PM which is not good. i want to show time same like 12:09 and 12:06.
my render function to format datetime is below.
"render": function (data) {
var date = new Date(data);
var month = date.getMonth() + 1;
return date.getDate() + "/" + (month.length > 1 ? month : month) + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + " " + data.slice(-2);
}
This question has an accepted answers - jump to answer
Answers
Ah good old dates in raw javascript. You might be best served by using Moment.JS as it takes all the pain of messing around with dates and time in Javascript away.
If however, that is all you want to do including another library might be overkill. If so, then just define a
pad
function that will add a0
at the start of numbers less than 10.Allan