Ramakrishnan
Ramakrishnan

Reputation: 5436

How to get locale using Php

How to get Locale using Php,I want to get the time zone based on the location, is there any possibility to get in php.

I need to convert it to GMT and save Database.Again i need to Pull it back to UI with same time same time zone.

Upvotes: 16

Views: 37449

Answers (3)

Pol
Pol

Reputation: 541

Using

setlocale  (LC_ALL,"0");

to get in the result the actual locale.

Upvotes: 54

Sarfraz
Sarfraz

Reputation: 382636

You can use:

date_default_timezone_set('Europe/London');
date_default_timezone_get; // Europe/London

or

if (ini_get('date.timezone')) {
    echo 'date.timezone: ' . ini_get('date.timezone');
}

Upvotes: 1

bobince
bobince

Reputation: 536339

You can't get the client's locale or timezone from the server side, and you can only make a guess at it from the client side, using JavaScript.

(You can get more locale information if the browser supports Java, but that's a bit of a pain and everyone hates applets.)

To handle timezones in a web application, store all your times as UTC timestamps, and convert them to text for on-page formatting using a user-chosen timezone. You can use methods like in this question to guess at the timezone, but since this is not reliable you should also allow the user to explicitly choose timezone.

Upvotes: 1

Related Questions