Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert timestamp into hour with PHP

Tags:

php

timestamp

Hi I am using following way to convert timestamp into hour:

 echo time() / 3600 % 24;

This return like 7 if its 7 GTM but I need its output such as 07:00

Please suggest.

Thanks!

like image 377
jas Avatar asked Mar 23 '26 04:03

jas


1 Answers

you can do this with gmdate function

echo gmdate("H:i", time());

if you want only hours than just have only H in gmdate

gmdate — Format a GMT/UTC date/time

Demo

As @Mark Baker suggest if you want fix second timer than you can manually write like

echo gmdate("H:00", time());
like image 126
NullPoiиteя Avatar answered Mar 25 '26 18:03

NullPoiиteя



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!