Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  137] [ 1]  / answers: 1 / hits: 32789  / 11 Years ago, mon, august 26, 2013, 12:00:00

I have this backend that sends me a pre formatted time in a set time zone, but without any information for the said time zone. The strings are like: 2013-08-26 16:55:00.



I can create a new moment.js instance with this string:



var time = moment(2013-08-26 16:55:00) //this creates time in my tz


but this will only create an instance in my own time zone.



Moment.js have a plugin that can create instances of the object in specific time zones and it works great, but I can't say what time I want the object to point to.



If I'm in New York and I do this:



var time = moment(2013-08-26 16:55:00).tz(America/Los_Angeles);


the resulting time will be 13:55 instead of 16:55 but in LA.



What I want is to create an instance that will say 16:55, but in LA time.



The reason I'm asking is because I want to do this:



var now = moment.tz(America/Los_Angeles);
var end = moment(2013-08-26 16:55:00); //plus something to convert LA time

var timeLeft = end.diff(now, minutes);


Is there a way to do that?


More From » timezone

 Answers
12

In most cases, you can simply do this:



moment.tz(2013-08-26 16:55:00, America/Los_Angeles)


If you require input other than ISO8601, then specify the format string as the second parameter, and the time zone as the third:



moment.tz(8/26/2013 4:55 pm, M/D/YYYY h:mm a, America/Los_Angeles)


And if you need to use moment's strict parsing mode, then that goes in the third parameter, and the time zone moves to the fourth position:



moment.tz(8/26/2013 4:55 pm, M/D/YYYY h:mm a, true, America/Los_Angeles)

[#76120] Sunday, August 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
elishaannac questions
Sun, Dec 5, 21, 00:00, 3 Years ago
Mon, Jun 14, 21, 00:00, 3 Years ago
Mon, Jul 22, 19, 00:00, 5 Years ago
Mon, Jul 8, 19, 00:00, 5 Years ago
;