Tôi muốn hiển thị Thời gian ở định dạng 12 giờ bằng cách thay đổi mã sau. i Đã thử các kỹ thuật khác nhau nhưng không may mắn, hy vọng sẽ tìm được giải pháp từ các bạn.Thời gian hiển thị ở định dạng 12 giờ trong JavaScript
<script type="text/javascript">
$.fn.androClock = function() {
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"];
function getTime() {
var date = new Date(),
hour = date.getHours();
return {
day: days[date.getDay()],
date: date.getDate(),
month: months[date.getMonth()],
hour: appendZero(hour),
minute: appendZero(date.getMinutes())
};
}
function appendZero(num) {
if (num < 10) {
return "0" + num;
}
return num;
}
function refreshClock() {
var now = getTime();
$('#date').html(now.day + "<br>" + now.date + '. ' + now.month);
$('#time').html(now.hour + ":" + now.minute);
setTimeout(function() {
refreshClock();
}, 10000);
}
refreshClock();
};
$('#andro-clock').androClock();
</script>
thể trùng lặp của [Thay t quân sự ime đến thời gian bình thường với Javascript] (http://stackoverflow.com/questions/14415618/replace-military-time-to-normal-time-with-javascript) –