0

I am trying to display a time in the current named timezone using moment timezone.

The time is stored in the database in UTC as 2014-07-22 11:11:06. Whatever I try I cannot display the time as 12:11 even though the named timezone is Europe/London.

var timestamp = 1406023866000; // converted from database stored as UTC 2014-07-22 11:11:06 var zone = tz.name(); // Europe/London var utc = moment(timestamp); // create a moment from the timestamp var time = utc.tz(zone); // _d: Date {Tue Jul 22 2014 12:11:06 GMT+0100 (GMT Standard Time)} // _f: undefined // _i: 1406023866000 formatted = time.format('h:mma'); // 11:11am - should be 12.11pm because of BST 
2
  • Have you tried providing a string to tz.name? Explicitly name your timezone? Commented Jul 22, 2014 at 12:05
  • Just tried that and made no difference var time = utc.tz("Europe/London"); Commented Jul 22, 2014 at 12:07

1 Answer 1

1

Assuming that your timestamp is in milliseconds, 1406023866000 = GMT: Tue, 22 Jul 2014 10:11:06 GMT.

I used http://www.epochconverter.com/

Sign up to request clarification or add additional context in comments.

3 Comments

Changing the timezone in php from Europe/London to UTC seems to have fixed the issue somehow.
Congrats. When I converted your timestamp - using the website above - the ceonverted date was ONE HOUR EARLIER than you posted in your question. fyi
Yeh it was driving me crazy. I assumed that date('U', strtotime($conversation_data['updated'])) * 1000; was creating the timestamp in UTC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.