Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Unix Conversion

Featured Replies

Hey,

 

Basically i'm making something for a gaming communuity, who have a database which holds info from their servers.

 

The one thing i'm stuck on is this:

 

All players have a "total connection time", however the number stored in the database is of a unix 32 bit timestamp.

 

Now, I know the php date/time function can convert this, but I want it in a certain format that I cant work out.

 

Heres an example:

 

Connection Time 32 bit = 212675

Needs to be converted to = 2d 11:04:35h

 

Thats what the stats website provides, but I need to work out how to convert it myself.

 

Anyone got a clue?

Are you using PHP 5.3?

 

$d1 = new DateTime();
$d2 = new DateTime();
$d2->add(new DateInterval('PT212675S'));

$interval = $d2->diff($d1);

echo $interval->format('%dd %H:%I:%Sh');

Edited by Jock

****ty simple :p

$days = (int) ($time / 86400.0);
$time -= $days * 86400;
$hours = (int) ($time / 3600.0);
$time -= $hours * 3600;
$minutes = (int) ($time / 60.0);
$time -= $minutes * 60;
$seconds = $time;

echo "{$days}h {$hours}:{$minutes}:{$seconds}";

  • Author

Ah thanks Jock, yours worked perfect :)

 

Although cepa im sure that worked although I wasnt sure how to implement the number xD

 

Thanks, you guys saved me again ;)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.