I am working on an app which needs a certain functionality related to time & timezones. Here is a pseudo code below which may provide brief about my doubt
$start_time = "10:00 AM"; // starting time of an event
$end_time = "11:00 AM"; // ending time of an event
$system_time = "1:30 AM";
$timezone = "India +5:30";
What I want is to show the status of the event as "Live" , "Upcoming" and "Finished" based on whether event is currently going on, is going to happen or has already happened.
How can I find this status independent of the timezone of the country ?
Any way In which I could have an universal function like
$universal_time = get_time_in_utc_for($system_time, $timezone); // similarly for start_time & end_time
You have a good start - use UTC.
Traditionally strtotime()
is the method for the job. However, if you are using PHP > 5.3, you might find the DateTime class to be more flexible.
A quick code sample:
$timestamp = strtotime('2013-03-28 10:00 AM +5:30');
// 1364445000