Advertisement
albin900

SCRIPT

Sep 24th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2. $channel = "behkuhtv";
  3.  
  4. $data = file_get_contents("https://api.twitch.tv/kraken/streams/{$channel}");
  5. $json = json_decode($data);
  6.  
  7. if($json->stream != null){
  8. date_default_timezone_set("Europe/Stockholm");
  9.  
  10. $date = date_create($json->stream->created_at);
  11.  
  12. $start = date_timestamp_get($date);
  13.  
  14. $time = time() - $start;
  15.  
  16. for($i=0;$i<100;$i++){
  17. if($time > (60 * 60 * 24)){
  18. $days++;
  19. $time = $time - (60 * 60 * 24);
  20. }
  21.  
  22. if($time > 3600){
  23. $hours++;
  24. $time = $time - 3600;
  25. }
  26.  
  27. if($time > 60){
  28. $minutes++;
  29. $time = $time - 60;
  30. }
  31. }
  32.  
  33. $str = "Current uptime: ";
  34.  
  35. if($days != null){
  36. $str .= "{$days}d ";
  37. }
  38.  
  39. if($hours != null){
  40. $str .= "{$hours}h ";
  41. }
  42.  
  43. if($minutes != null){
  44. $str .= "{$minutes}m ";
  45. }
  46.  
  47. if($time > 0){
  48. $str .= "{$time}s ";
  49. }
  50.  
  51. $str .= "since " . $date->format('d/m/y');
  52.  
  53. echo $str;
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement