0

I have a string representing a UTC date:

'2016-07-29T01:33:56.72'

I would like to display this date corrected to my timezone and nicely formatted:

'2016-07-28 22:33:56'

I tried libraries like moment.js or numeral.js but I still didn't found a clear way to do it. My problem so far is that I am starting with a string object and not a Date object.

Bruno
  • 4,685
  • 7
  • 54
  • 105
  • Answered here for moment.js: http://stackoverflow.com/questions/29220467/how-to-convert-moment-js-date-to-users-local-timezone – Tatjana N. Jul 29 '16 at 02:42
  • oh wow thanks, didn't see that, do you want to add the answer – Bruno Jul 29 '16 at 02:52
  • There are many approaches, but likely the simplest is to parse the string to a Date, then create a [*formatted string*](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript). A date library can help (e.g. [*Fecha.js*](https://github.com/taylorhakes/fecha) is small and does parsing and formatting), but you really only need about 10 lines of code. – RobG Jul 29 '16 at 02:58

1 Answers1

0

Answered here for moment.js: How to convert Moment.js date to users local timezone?… – Voyta

Community
  • 1
  • 1
Bruno
  • 4,685
  • 7
  • 54
  • 105