Skip to content Skip to sidebar Skip to footer

Create Moment Object From Utc String

I'm getting from my webservice an UTC date String such as the following : '2015-06-06T12:30:12Z' I need to display it following these 2 rules : If date < 1 week, display it

Solution 1:

You're just hitting a bug, already logged as #2367.

Stated very simply, it's using the last locale loaded ("zh-tw"), rather than defaulting to English.

Simply call add the following line after you load moment but before you use it anywhere.

moment.locale('en');

This sets the language back to English.

That explains the output of the fromNow string. The other output is because you concatenated the moment object directly with another string, which implicitly calls .valueOf(), which returns the UTC-based timestamp in milliseconds. You should instead use .format(), perhaps with an argument such as .format("YYYY-MM-DD") - if that's the output format you would like to see.

Post a Comment for "Create Moment Object From Utc String"