Skip to content

Instantly share code, notes, and snippets.

@karthicksivakumar191194
Last active September 27, 2021 11:28
Show Gist options
  • Save karthicksivakumar191194/c0b1c1df72df449395fa3609251cd813 to your computer and use it in GitHub Desktop.
Save karthicksivakumar191194/c0b1c1df72df449395fa3609251cd813 to your computer and use it in GitHub Desktop.
Helper to get railway time using PHP
<?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