-1

I'm trying to get the date time based on user's timezone.I have tried with

echo date('Y-m-d H:i:s');

It is displaying correct date but the time is incorrect.May be it is taking server's timezone by default.Can anyone suggest me the better way to do it.

GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • 1
    here is a similar question [link](http://stackoverflow.com/questions/2705067/how-can-i-get-the-users-local-time-instead-of-the-servers-time) – ste1inbeck Oct 07 '14 at 06:30

2 Answers2

3

PHP is a server side language, so basically yo dont have any function that do it. you have to make the user send his time or timezone to you. for example, you can do it with ajax like here, javascript is a client side language that runs on the user computer and gets his time, then sends it to the server.

another way is to get the location of the user by his IP, there are many libraries that do it, for example this one, and create the date from his location

Community
  • 1
  • 1
Dima
  • 8,586
  • 4
  • 28
  • 57
0

you can set default timezone and get time also what you want. suppose you want riyadh timezone then you can get by this code. you can put other timezone also what you want .here is the code

   date_default_timezone_set('Asia/Riyadh');

here is list of timezome

http://php.net/manual/en/timezones.php

Lokesh Jain
  • 579
  • 6
  • 19