x
1
<h2>字符串转换为 Date 对象</h2>
2
3
<p id="demo"></p>
4
5
<script>
6
var text = '{ "name":"Mifengjc", "initDate":"2013-12-14", "site":"www.mifengjc.com"}';
7
var obj = JSON.parse(text, function(key, value) {
8
if (key == "initDate") {
9
return new Date(value);
10
} else {
11
return value;
12
}
13
});
14
document.getElementById("demo").innerHTML = obj.name + "创建日期:" + obj.initDate;
15
</script>