Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $channel = "behkuhtv";
- $data = file_get_contents("https://api.twitch.tv/kraken/streams/{$channel}");
- $json = json_decode($data);
- if($json->stream != null){
- date_default_timezone_set("Europe/Stockholm");
- $date = date_create($json->stream->created_at);
- $start = date_timestamp_get($date);
- $time = time() - $start;
- for($i=0;$i<100;$i++){
- if($time > (60 * 60 * 24)){
- $days++;
- $time = $time - (60 * 60 * 24);
- }
- if($time > 3600){
- $hours++;
- $time = $time - 3600;
- }
- if($time > 60){
- $minutes++;
- $time = $time - 60;
- }
- }
- $str = "Current uptime: ";
- if($days != null){
- $str .= "{$days}d ";
- }
- if($hours != null){
- $str .= "{$hours}h ";
- }
- if($minutes != null){
- $str .= "{$minutes}m ";
- }
- if($time > 0){
- $str .= "{$time}s ";
- }
- $str .= "since " . $date->format('d/m/y');
- echo $str;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement