2016年2月

新浪天气预报API

新浪天气预报API 很实用
返回是xml文件 utf8字符编码

//// xml 解析提取内容

$xml = new DOMDocument();
//新浪天气接口 返回是xml格式 编码为utf-8
$xml->load('http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0');

foreach($xml->getElementsByTagName('status1') as $list)
{
$tq = $list->firstChild->nodeValue;

}
$strtq = iconv("UTF-8", "GB2312//IGNORE", $tq);

js获取当前日期和星期

var myDate = new Date();
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.toLocaleDateString();
var days = myDate.getDay();
if(days=='5'){
days = "五";
}else if(days=='4'){
days = "四";
}else if(days=='3'){
days = "三";
}else if(days=='2'){
days = "二";
}else if(days=='1'){
days = "一";
}else if(days=='6'){
days = "六";
}else{
days = "日"
}

document.write("北京时间:"+myDate.toLocaleDateString().replace(///g,".")+" 周"+days);