I want to be able to format the time data that i get from SQL server time datatype with moment.js what i get is "PS12H:30M" when i try to format that with moment.js i get "Invalid Date", can you please help me?

Javascript

moment("PS12H:30M").format('hh:mm A');

Database

[from]               TIME (1)     NOT NULL
[to]                 TIME (1)     NOT NULL
有帮助吗?

解决方案

You have to parse the String, since "PS12H:30M" isn't a recognized format. Pass a parse String as the second parameter to moment, like this:

moment("PS12H:30M", "HH:mm").format('hh:mm A');

"12:30 PM"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top