Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  82] [ 5]  / answers: 1 / hits: 110207  / 8 Years ago, thu, october 20, 2016, 12:00:00

I used MomentJS to convert local date to UTC date using the following way:





$(#div1).text(moment(2016-10-11 18:06:03).tz(Europe/Paris).format());

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.6/moment-timezone-with-data.min.js></script>

<div id=div1></div>





Now I need timestamp from the output value using MomentJS.


More From » momentjs

 Answers
8

You said:




I used MomentJS to convert local date to UTC date using the following way:
moment(2016-10-11 18:06:03).tz(Europe/Paris).format()




That doesn't do that. That converts a local value to Paris time, and emits it as a string in ISO8601 format.




Now I need timestamp from the output value using MomentJS.




That's a different question, and wouldn't involve the output of the above because:




  1. You can't get a timestamp from the output string, you'd get it from a moment object. You could parse that string, but that would be silly since you already had a moment object earlier.


  2. Timestamps are UTC based, so time zone conversion is irrelevant. You'd get the same timestamp if you didn't convert at all.




You can get a string with a timestamp using .format('X') or .format('x') depending on which precision you want. But it's much cleaner to just get the numerical timestamp using .valueOf() or .unix(), again depending on precision.


[#60338] Monday, October 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micah

Total Points: 295
Total Questions: 104
Total Answers: 92

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
micah questions
Mon, Jan 24, 22, 00:00, 2 Years ago
Thu, Dec 31, 20, 00:00, 4 Years ago
Thu, Aug 27, 20, 00:00, 4 Years ago
Wed, Apr 15, 20, 00:00, 4 Years ago
;