Reputation: 7631
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);
This returns me Thu Oct 06 2011 02:10:00 GMT+0530 (India Standard Time)
I want to extract this 02:10:00
and convert this into time like this 9:30 P.M or A.M
Upvotes: 0
Views: 83
Reputation: 32143
Can't you just try something like this?
<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>
Upvotes: 3
Reputation: 26591
To display time with AM / PM, you can use this kind of script:
var hours = newDate.getHours()
var minutes = newDate.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
Upvotes: 1