-8

I have an SMS site, that allows people send SMS. I want to add a schedule feature, where people can write the time they want their SMS to be sent. Everything will be stored in the database that is the message and time. I will create a cron job that will run a PHP script every minute and check if there are scheduled SMS. I will take the country code of the destination phone number and convert it to a country name.

My question is: how can I get the current time of a particular country by its name. I have searched Google, but no good answer. Am scared of using a free date & time API.

hakre
  • 193,403
  • 52
  • 435
  • 836
Elvis Chidera
  • 27
  • 1
  • 7
  • 8
    There's never going to be a situation in which it's appropriate to write full sentences in uppercase on Stack Overflow. Please don't do that. – user229044 Apr 24 '13 at 12:56
  • So what time should it return for the USA now? – Mark Baker Apr 24 '13 at 12:57
  • Use DateTimeZone http://stackoverflow.com/questions/2826419/country-to-timezones-in-php-zend-framework – nvanesch Apr 24 '13 at 13:00
  • By a country name? What if the user is in russia? Russia got more than 8 time zones. By more specific please – Kingalione Apr 24 '13 at 13:00
  • This is essentially what you want to do: http://stackoverflow.com/questions/14589678/in-php-how-can-i-get-timezone-from-offset-and-country – Joe Phillips Apr 24 '13 at 13:01
  • See as well: [How to find GMT date/time by country name?](http://stackoverflow.com/q/3483519/367456) – hakre Apr 24 '13 at 13:38

1 Answers1

2

Why don't you just convert the schedule time to localtime before inserting to the database? Would save you a lot of unnecessary date operations.

Also, some countries (USA, Russia, China) have more than one time zone.

Glitch Desire
  • 14,632
  • 7
  • 43
  • 55
  • There isnt much more to explain. Get the user to choose a time and timezone he wants to send to, then convert to `localtime` and store, then just compare your SMSs to localtime on the `cron`. – Glitch Desire Apr 24 '13 at 13:03
  • China only has one time zone for the entire country and some time zones will shift due to daylight savings time. – Joe W Apr 24 '13 at 13:05
  • Xinjiang and Tibet usually don't use Unified time, but technically you're correct. – Glitch Desire Apr 24 '13 at 13:07
  • Thats what am trying to avoid. I don't want the user to worry about timezone, i wan't to do that internally. But anyway, i am a php beginner, do you mind putting your solution in code incase its my last option ? – Elvis Chidera Apr 24 '13 at 13:13
  • 1
    Were you planning to rely on auto detection for timezone? Not all people's IPs geolocate to their current time zone (VPNs, tor, proxies etc). At very least you should show the current time you've detected and allow the user to change it. – Glitch Desire Apr 24 '13 at 13:20