Date.parseWeird = Date.prototype.parseWeird = function (d) {
return new Date(parseInt(d.replace(/[^\-\d]/g, ""), 10));
};
var newDate = Date.parseWeird("\/Date(1317847200000-0400)\/");
document.write(newDate);
这会返回我Thu Oct 06 2011 02:10:00 GMT+0530(印度标准时间)
我想提取此 02:10:00
并将其转换为时间,如 9:30 P.M 或 A.M
最佳答案
你就不能尝试一下这样的事情吗?
<h4>It is now
<script type="text/javascript">
<!--
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
//-->
</script>
</h4>
关于javascript - 从日期响应中提取时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7688270/