Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert time to local time given city/state/country [duplicate]

I'd like to write a function that can convert a time in EST (USEast Standard Time) to a time in another local timezone.

The inputs will be "time in EST" in the form 'Y-m-d H:i:s' (i.e. 2011-08-23 05:05:35), "City" "State", and "Country"

The function should return the local time (i.e. if the city, state, country is San Francisco, California, USA, and time in EST is 2011-08-23 05:05:35, function should return 2011-08-23 02:05:35)

I tried to figure it out from php.net but it seems like I need a continent to specify a timezone...and I didn't know how to convert a country to a continent.

Thanks

like image 873
Mark Avatar asked Aug 25 '11 21:08

Mark


People also ask

How do I convert time to local time in Excel?

To do this, select the cell that contains the date and time that you want to convert. Then click on the Formulas tab and select Insert Function. In the Insert Function dialog box, scroll down until you see the TIMEVALUE function and select it. Click OK.

How do I get a specific timezone offset?

JavaScript Date getTimezoneOffset() getTimezoneOffset() returns the difference between UTC time and local time. getTimezoneOffset() returns the difference in minutes. For example, if your time zone is GMT+2, -120 will be returned.

How do I convert UTC time to local time in SQL?

SELECT CONVERT(datetime, SWITCHOFFSET(CONVERT(DATETIMEOFFSET, GETUTCDATE()), DATENAME(TZOFFSET, SYSDATETIMEOFFSET()))) AS LOCAL_IST; Here, the GETUTCDATE() function can be used to get the current date and time UTC. Using this query the UTC gets converted to local IST.


2 Answers

the PHP function date_default_timezone_set('EST'); accepts timezone as EST or GMT maybe this can be a good alternative to your problem.

like image 59
Book Of Zeus Avatar answered Sep 21 '22 18:09

Book Of Zeus


I prefer:

date_default_timezone_set('America/Los_Angeles');
like image 39
Pat R Ellery Avatar answered Sep 20 '22 18:09

Pat R Ellery