Last active
September 27, 2021 11:28
-
-
Save karthicksivakumar191194/c0b1c1df72df449395fa3609251cd813 to your computer and use it in GitHub Desktop.
Helper to get railway time using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getRailwayTime($time){ | |
$am = explode('am',str_replace(array('am','Am','aM', 'AM'),'am', $time)); | |
$pm = explode('pm',str_replace(array('pm','Pm','pM', 'PM'),'pm', $time)); | |
$output = 0; | |
if(isset($am[1])){ | |
$output = $am[0]; | |
}else if(isset($pm[1])){ | |
if((int)$pm[0] > 0){ | |
if((int)$pm[0] < 12){ | |
$output = (int)$pm[0] + 12; | |
}else if((int)$pm[0] === 12){ | |
$output = (int)$pm[0]; | |
} | |
} | |
} | |
return $output; | |
} | |
echo getRailwayTime("1pm"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment