简体   繁体   中英

Javascript: How do I convert a specific timezoned date to different time zone date?

I have a php script which gives server time, but as per knowledge, we can get the user's machine time and time zone with the help of client side scripts (javascript). I have mysql table which has dates stored along with timezone from where it was stored with the help of form. I need to show the data on a web page along with the time stored in the table, but it should be per user's machine.

rowid | date | timezone | data |
----------------------------------
12  | 2010-07-13 12:30:00 | Asia/Kolkata | This is data field |
143 | 2010-07-13 12:30:00 | Europe/Prague | This is data field |

Now, when I show date on web page, I need to show the above date per user's machine timezone.

A workaround logic would be that, if I could pass the date (2010-07-13 12:30:00) to some JS method which will take two time zone as input and convert the given date into user's machine's timezone. Or Something else?

Please help?

See the following link:

http://us3.php.net/manual/en/function.date-timezone-set.php

You can set the timezone in the script before displaying the dates although make sure you insert all the times in the DB as GMT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM