0

how to convert Time format H:MM to HH:mm format if it is showing in single digit. For example I want to show 9:00 AM as 09:00 AM.

My input should be 9:00 AM and output should be 09:00 AM.

Raj
  • 183
  • 3
  • 17

2 Answers2

0

var newDate = new Date();  
console.log("0" + newDate.getHours());

Use Date(). It might help you.

Hearner
  • 2,711
  • 3
  • 17
  • 34
  • I am not using Date(). I am receiving string data like 12:10 AM from service call and have to convert in specific format. – Raj Apr 12 '17 at 07:49
0

Moment.js (https://momentjs.com/) is normally my go-to library for Date parsing.

Not sure exactly what your output format is in full, but something like the following should do the trick:

moment("1/5/15 9:3:4", "D/M/YY h:m:s").format("DD/MM/YYYY hh:mm:ss") == "01/05/2015 09:03:04"
tr00st
  • 331
  • 4
  • 15