javascript - Momentjs changes the timezone value -


i have these lines of code

const starttime = '2017-09-12t09:00:00-04:00'; let s = moment(starttime); s.format()

these lines output '2017-09-12t13:00:00+00:00'

how can still output previous string? '2017-09-12t09:00:00-04:00'

i've tried going through documentation , tried using utcoffset() s.utc().format() after looking @ other answers on stackoverflow

i perform add operation on time doesn't seem relevant @ "moment".

var starttime = '2017-09-12t09:00:00-04:00';  var s = moment.parsezone(starttime);  s = s.add(1, 'd');  console.log(s.format()); //2017-09-13t09:00:00-04:00    starttime = '2017-09-12t09:00:00+00:00';  s = moment.parsezone(starttime);  console.log(s.format('yyyy-mm-ddthh:mm:ssz'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

moment's string parsing functions moment(string) , moment.utc(string) accept offset information if provided, convert resulting moment object local or utc time.

in contrast, moment.parsezone() parses string keeps resulting moment object in fixed-offset timezone provided offset in string.

-- moment.js docs


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -