Skip to content
Advertisement

Don’t display time if midnight using Moment.js

How do I use http://momentjs.com/docs/ to only display the time if it is not midnight? For instance, please look at the first example below.

JavaScript

A possible non-elegant solution would be to use JavaScript to check if the datetime trails with 00:00:00, and if so, provide a format string of ‘MM/DD/YYYY’ instead of ‘MM/DD/YYYY h:mm:ss A’, but I expect there is a more proper way to do so.

Advertisement

Answer

There are many ways. Here’s one way (concise enough for most purposes):

JavaScript
Advertisement