参照:東京電力電力供給状況API http://tepco-usage-api.appspot.com/
東京電力の電気使用状況 APIより最新の電力使用状況をjQueryで取得して表示する例です。日付はUTC形式なので、ローカルタイムに変換して表示しています。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>Twitter REST API:タイムライン関連:public_timeline(最新のつぶやきを取得) | 設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <!-- JS --> <script type="text/javascript"> $(function(){ var url="http://tepco-usage-api.appspot.com/latest.json?callback=?"; var jqxhr = $.getJSON(url, function(data) { var s=""; s="計画停電の有無 data.saving="+data.saving+"<br>"; s+="年 data.year="+data.year+"<br>"; s+="月 data.month="+data.month+"<br>"; s+="日 data.day="+data.day+"<br>"; s+="時刻(24時間制、日本時間) data.hour="+data.hour+"<br>"; s+="この時刻の文字列 data.entryfor="+utctolocal(data.entryfor)+" (元データUTC->ローカルタイムに変換後の値)<br>"; s+="供給力情報更新日 data.capacity_updated="+utctolocal(data.capacity_updated)+"(元データUTC->ローカルタイムに変換後の値)<br>"; s+="最大の供給能力を発揮する予定の時刻 data.capacity_peak_period="+(data.capacity_peak_period)+"<br>"; s+="供給可能最大電力(万kW) data.capacity="+data.capacity+"<br>"; s+="この時間帯の消費電力(万kW) data.usage="+data.usage+"<br>"; s+="この消費電力のデータが更新された日時 data.usage="+utctolocal(data.usage_updated)+"(元データUTC->ローカルタイムに変換後の値)<br>"; $("#res").html(s); }) }); function utctolocal(str){ var d=new Date(str); var tmp=new Date(d.getTime()-(d.getTimezoneOffset()*60*1000)); return tmp.getFullYear()+"年"+(tmp.getMonth()+1)+"月"+tmp.getDate()+"日 "+tmp.getHours()+"時"+tmp.getMinutes()+"分"+tmp.getSeconds()+"秒"; } </script> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <p>参照:東京電力電力供給状況API <a href='http://tepco-usage-api.appspot.com/'>http://tepco-usage-api.appspot.com/</a></p> <p>東京電力の電気使用状況 APIより最新の電力使用状況をjQueryで取得して表示する例です。日付はUTC形式なので、ローカルタイムに変換して表示しています。</p> <!-- CODE --> <div id="res"></div> <!-- / CODE --> </div> </body> </html>