Reputation: 4318
https://codepen.io/anon/pen/ajMEyo?editors=0012
I pass in 0 like moment(0).format('HH:mm a')
and this transforms to "01:00 am". I linked a codepen just incase.
The actual momentjs object looks like
Moment {_isAMomentObject: true, _i: 0, _isUTC: false, _pf: {…}, _locale: Locale, …}
But when I try to format it, to display, it transforms it to 01:00 am
. I'm passing in 0. As in, 0 seconds have elapsed therefore, i'm expecting 00:00:00
as the start of the day. But It's being transformed at some point and I don't see mention of this in the docs.
Upvotes: 0
Views: 70
Reputation: 10703
This could have something to do with the timezone you are in. The 01:00 am
makes it looks like you are in a timezone which UTC+1
With moment().utcOffset()
you can determine your offset to UTC. Perhaps this is 1 hour. You can use moment().local()
to get your times in local timezone.
Upvotes: 1
Reputation: 62213
See the Documentation of what you are actually calling
Unix Timestamp (milliseconds)
Similar to new Date(Number), you can create a moment by passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
moment(0).toString()
Output
Wed Dec 31 1969 19:00:00 GMT-0500
If you want the beginning of todays date you should use startOf
Start of Time
Mutates the original moment by setting it to the start of a unit of time.
moment().startOf('date').toString()
Output
Mon Aug 13 2018 00:00:00 GMT-0400
Upvotes: 0