Papouche Guinslyzinho
Papouche Guinslyzinho

Reputation: 5448

formatting json date adding a 0

Hi I have an Handlebar helper call findHour that will return the hour as hh:mm but for 2:4 (2hrs40) it doesn't add the 0 at the end of it.

var heure_intervention = "2000-01-01T07:04:57Z"


   Handlebars.registerHelper( "findHour", function ( heure_intervention ){
        a= new Date(heure_intervention);
        return (a.getHours() +":"+ a.getMinutes());
    });

fiddle

Upvotes: 0

Views: 35

Answers (1)

Artem Petrosian
Artem Petrosian

Reputation: 2954

Try this solution:

...
return ( ( '0' + a.getHours() ).slice(-2) +":"+ ( '0' + a.getMinutes() ).slice(-2));

Upvotes: 1

Related Questions