I have tried moment.time(column.start_time).format("hh:mm A")
but it give me error.
I have custom time field value is "15:30:00" want to format like "03:30 PM".
To get the current date and time, just call javascript moment() with no parameters like so: var now = moment(); This is essentially the same as calling moment(new Date()) . Unless you specify a time zone offset, parsing a string will create a date in the current time zone.
Date Formatting Date format conversion with Moment is simple, as shown in the following example. moment(). format('YYYY-MM-DD'); Calling moment() gives us the current date and time, while format() converts it to the specified format.
The moment(). hour() Method is used to get the hours from the current time or to set the hours. Syntax: moment().hour(); or. moment().
defaultFormat = "YYYY" 'YYYY' > moment().
You need to add a format string into the moment
function because your date is not a valid ISO date.
var time = "15:30:00"; var formatted = moment(time, "HH:mm:ss").format("hh:mm A"); console.log(formatted);
<script src="https://momentjs.com/downloads/moment.min.js"></script>
I will include one more additional information:
When you use hh:mm A
var time = "15:30:00"; var formatted = moment(time, "HH:mm").format("hh:mm A"); console.log(formatted); //it will return 03:30 PM
And when you use LT
var time = "15:30:00"; var formatted = moment(time, "HH:mm:ss").format("LT"); console.log(formatted); //it will return 3:30 PM
The difference between one and another is just a 0 before the first number when it is lower then 10. I am working with date time picker and then I understood why it was not binding in my combo box.
More details in: https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/#localized-formats
I hope it can help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With