I have a problem with timestamp. Suppose a user uploads a picture somewhere in USA at 4.30 am and if another user sees this picture in Japan. It would show 4.30 am as the date saved in database would be 4.30 am but it should be 4.30 pm to the Japanese people, as they are 12 hours ahead of America.
So I was thinking to get the current server time using PHP, let’s say it is a and also get the current time of user using JavaScript functions say it is b and then find the difference between b and a and that result should be added to the date stored in the database.
So server may show 4.30 am and js function gives 4.30 pm it would give 12 hrs difference so this 12 hrs should be added to the date saved in the database.This is what I thought of doing but I’m not sure if there are any inbuilt plugins in doing the task because every site will be using this type of feature may be they might be using someone’s open source code.
Also there might be any other better solutions? And is my algorithm right? I was thinking it is little bit time consuming getting the difference and adding those to all the posts would be little time consuming.
Store all time stamps as UTC. Then for the user interface do the correction for the particular time zone for the user. You can also take into account day light savings if necessary