ballouta Posted July 21, 2008 Share Posted July 21, 2008 Hello I need to print my local time (lebanon) on the following format: 3:17 pm how i can make it please? thank you Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/ Share on other sites More sharing options...
jandrews3 Posted July 21, 2008 Share Posted July 21, 2008 Try the following. The variable $differencetolocaltime is equal to the time difference between your server and you. <?php $differencetolocaltime=4; $new_U=date("U")-$differencetolocaltime*3600; print date("H:i", $new_U); ?> Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595431 Share on other sites More sharing options...
ballouta Posted July 21, 2008 Author Share Posted July 21, 2008 how do i assign this time to a variable? thank you Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595494 Share on other sites More sharing options...
redarrow Posted July 21, 2008 Share Posted July 21, 2008 <?php $time=date("h:m:s"); echo $time; ?> Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595497 Share on other sites More sharing options...
ballouta Posted July 21, 2008 Author Share Posted July 21, 2008 redarrow's code works but doesn't give me my local time, the first code is correct but I need to assign teh value to a variable inorder to insert it into a DB. thanks Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595502 Share on other sites More sharing options...
redarrow Posted July 21, 2008 Share Posted July 21, 2008 <?php date_default_timezone_set('lebanon'); $time=date("h:m:s"); echo $time; ?> Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595509 Share on other sites More sharing options...
ballouta Posted July 21, 2008 Author Share Posted July 21, 2008 sorry but the above code gave me this: 10:07:17 which is NOT my correct time Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-595514 Share on other sites More sharing options...
ballouta Posted July 22, 2008 Author Share Posted July 22, 2008 any help plz Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-596259 Share on other sites More sharing options...
ballouta Posted July 22, 2008 Author Share Posted July 22, 2008 thanks for jandrews3 <?php $differencetolocaltime=4; $new_U=date("U")-$differencetolocaltime*3600; $date= date("H:i", $new_U); print $date; ?> Link to comment https://forums.phpfreaks.com/topic/115827-solved-print-time/#findComment-596730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.