Pure.Krome
Pure.Krome

Reputation: 86957

How does Twitter's Website calculate how long a tweet was posted?

Here's a screenshot of my twitter feed (as of right now while me writing this Question).

enter image description here

Notice how the time is relative to me, right now? (those times differences are correct, btw)

How do they calculate that?

The reason I ask is that right now, i'm in Melbourne Australia. When I Remote Desktop to a server in the states, log in to twitter (using the SAME account) .. i get the same results!

At first, I thought they were calculating this based upon my account settings for Time Zone (which btw is set at +10 GMT)

enter image description here

But if that was the case, when I remote desktop to the server (which is in San Fran, CA) it should be showing different results in that RD terminal, right?

So how could they have coded this, please?

Upvotes: 0

Views: 258

Answers (1)

casperOne
casperOne

Reputation: 74530

Twitter more than likely stores the date it was posted in UTC, it knows the time now in UTC (both on your machine and on the server).

Given that those date times are translated into the same timezone (UTC), it's a simple matter of taking the difference between the two times.

It's the same thing the Stack Exchange sites do to stamp the times for all the activities that you see.

As long as you're able to convert any representation of date time to UTC (which pretty much every API in existence has), this value is able to be computed as Twitter will push the UTC time down to the clients which then do the math (or do it on the server and pass the differences down); the settings that you see for UTC offset are when absolute times are displayed to you and you want them relative to your timezone.

Upvotes: 3

Related Questions