moment: BUG: fromNow() doesn't take care the timezone
How to reproduce I have a variable created returned from server in UTC format, example: 2018-02-15T00:30:31Z I want to display the time interval from created to user’s local time this is my code:
1: moment(_created_).local().fromNow()
2: moment(moment(_created_).local().toISOString()).fromNow()
3: var usertimezone = moment.tz.guess()
var value = moment.utc(_created_)
var formatDate = moment.tz(value, usertimezone)
return formatDate.fromNow()
All don’t work. I googled 3 hours, tons of people are bothered by this problem since 2013, and there is no solution, and this bug is not fixed.
Which is kind of disappointing for such a famous package.
Environment: Chrome 53 on OSX
If you are reporting an issue, please run the following code in the environment you are using and include the output:
console.log( (new Date()).toString())
console.log((new Date()).toLocaleString())
console.log( (new Date()).getTimezoneOffset())
console.log( navigator.userAgent)
console.log(moment.version)
Sat Feb 17 2018 03:45:28 GMT-0500 (EST)
2 2/17/2018, 3:45:28 AM
300
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
2.20.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (7 by maintainers)
@C0deZLee I thought of a couple more things to try.
Can you try these:
Hi 😃 I was having the same issue and solved it by using: moment(moment(date).local()).fromNow()