Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    What's wrong with .format("HH:mm")? Commented May 4, 2021 at 18:42
  • @HereticMonkey I will get an error "'isBetween' does not exist on type 'string'. when we perform the following code . inputTime.format("HH:mm").isBetween(beforeTime, afterTime); Commented May 4, 2021 at 19:05
  • The you don't need the formatted moment for that. Add the .format("HH:mm") only to where you show it in the view. Commented May 4, 2021 at 19:14
  • To put it another way. A moment object (what you have shown logged) wraps a Date object, which is the time value you parsed, arbitrarily set to today's date and put into the time zone of the browser. That moment object has functions like isBetween attached to it. It does not display the time formatted as you parsed it (technically, if you dig deep into that _pf property, you could probably find it, but that's implementation detail you should not depend on). When you call format, it takes the Date and time zone information and provides the time, formatted as desired. Commented May 4, 2021 at 19:32