﻿
function getToday(dformat) {
	var mydate= new Date();
	var theyear=mydate.getFullYear();
	var themonth=mydate.getMonth()+1;
	var thetoday=mydate.getDate();
	
	var myDays = ["Chủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bảy","Chúa  Nhật"];
	thisDay=mydate.getDay();
	thisDay=myDays[thisDay];
	
	dformat = dformat.replace('dow',thisDay);
	dformat = dformat.replace('dd',thetoday);
	dformat = dformat.replace('mm',themonth);
	dformat = dformat.replace('yy',theyear);

	return dformat;
}


//------------------------------------------------------
function getCurTime() {

 now = new Date();
  hour = now.getHours();
  min = now.getMinutes();
  sec = now.getSeconds();  
    if (min <= 9) {
      min = "0" + min; }
    if (sec <= 9) {
      sec = "0" + sec; }
    if (hour < 10) {
      hour = "0" + hour; }
      
var a_p = "";
var d = new Date();
var curr_hour = d.getHours();

a_p = (curr_hour < 12)?"AM":"PM";

if (curr_hour == 0)  curr_hour = 12;
curr_hour = (curr_hour>12)?curr_hour-12:curr_hour;
curr_hour = curr_hour + "";
curr_hour = (curr_hour.length==1)?"0"+curr_hour:curr_hour;


var curr_min = d.getMinutes();
curr_min = curr_min + "";
curr_min = (curr_min.length==1)?"0"+curr_min:curr_min;

var curr_sec = d.getSeconds();
curr_sec = curr_sec + "";
curr_sec = (curr_sec.length==1)?"0"+curr_sec:curr_sec;

return hour + ':' + min + ':' + sec;//curr_hour+':'+curr_min+':'+curr_sec+' '+a_p;
}

//------------------------------------------------------
function showDateTime() {
	
	document.getElementById('datetime').innerHTML = getToday('dow dd/mm/yy')+', '+getCurTime()+'';
	setTimeout('showDateTime()',1000);
}

 function formatTime() {
  now = new Date();
  hour = now.getHours();
  min = now.getMinutes();
  sec = now.getSeconds();  
    if (min <= 9) {
      min = "0" + min; }
    if (sec <= 9) {
      sec = "0" + sec; }
    if (hour < 10) {
      hour = "0" + hour; }
     
    document.aspnetForm.datetime.value = hour + ':' + min + ':' + sec;

  setTimeout("formatTime()", 1000);
}
