I have a string "Monday, April 28, 6:00pm - 11:00pm." I want to parse it into individual variables so I can format it and then convert it into UTC. Also, I only want the first part of the time. I figured a way to do it would be to explode it....

$arrayString = explode(',', $string);  //split string my comma
$startTime = explode(' - ', $arrayString[2]); //split time by using -
$times = $startTime[0];  
$date = strtotime($times);
echo date('g:ia', $date);  //Getting time

I want to output 06:00 pm (so I can test if $date works later for converting time to UTC). Yet I get 1:00am. When I try to do the same for Month, it gives me January.

Any suggestions? Thanks!

有帮助吗?

解决方案

You are creating $date only with reference to the time part of your string, hence it will default to January.

If you concatenate $arraystring[1] with your $times variable then you will probably get there.

Suggest you look at the DateTime class for your result variable as it will make time zone conversion easier.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top