Jump to content

[SOLVED] making a unix timestamp readable


blueman378

Recommended Posts

ok i am using a login system with admin features and one of it is i can view a table with all active users and it tells me how long thier last movement was however it is displayed in a unixtimestamp

 

so how would i make it more readable

 

the code is

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";
}

 

an example of the mysql database would be

 

usernamepassworduseriduserlevelemailtimestamp

user1e5a7537ed64e1587ff74d8b44e765143bbe9b4e9e96286a5b3998f41965ca1af1user1@gmail.com1190586395

user221232f297a57a5a743894a0e4a801fc3b1ae675a5ba50b31b72e8913861dc0479user2@gmail.com1190587801

 

if you need anything else please say.

 

thanks

matt

Link to comment
Share on other sites

im a little confused ???

 

so this should work?

 

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");
      $readable_time = date("m-d-Y", $time);

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n";
   }
   echo "</table><br>\n";
}

?

 

thanks your a great help

Link to comment
Share on other sites

I'm not really all that proficient with timezone issues, but there is a lot of info in the link I gave you.

 

In short, you wwill have to know the timezone the timestamp was created with (probably the server's timezone, so that should be the same all the time) and the timezone of the person in question. Then you need to calculate the difference, apply it and display it.

Link to comment
Share on other sites

ok well im just going to do it simpler

 

the server timezone is -4

my timezone is +12

 

so the difference is 16 hours

 

so how would i apply that ive been reading up and cant really do it, so here is my code please do what you can:

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");
      $readable_time = date("d-m-Y @ g:i:A", $time);

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n";
   }
   echo "</table><br>\n";
}

 

i was thinking of something like store the timezone in a variable eg $timechange = 16;

and then apply it to the hour (the seconds and minutes are right)

 

so would something like

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");
      $timechange = 16;
      $readable_time = date("d-m-Y @ g"+.$timechange.":i:A", $time);

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n";
   }
   echo "</table><br>\n";
}

 

but obviously it doesnt work,

so any help appreciated

 

cheers

matt

Link to comment
Share on other sites

ok well i found this little function

<?
  $timeZoneOffset = +16;

  $g = (date('H')+date('O'))+$timeZoneOffset; //hour
  $i = date('i'); //minutes
  $s = date('s'); //seconds
  $m = date('m');  //month
  $d = date('d') //day
  $Y = date('Y') //year
  $date = date('Y-m-d, g:i:s',mktime($g,$i,$s,$m,$d,$Y)); // will output somthing like 2007-09-13, 03:52:05
?>

 

so any idea how i would use it in here?

/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");
      $readable_time = date("d-m-Y @ g:i:A:Z", $time);

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n";
   }
   echo "</table><br>\n";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.