Programming Examples

JavaScript script to display the current day and time in the following format


Write a JavaScript script to display the current day and time in the following format. Sample Output : Today is : Friday. Current time is : 4 PM : 50 : 22

Solution

<!DOCTYPE HTML>
<html>
	<head>
		<title>Current Time</title>
		
	</head>
	<body>
	<script language="javascript">
	var current_date = new Date();
	var days =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
	var mode=["AM","PM"];
	var res;
	res="Today is:"+days[current_date.getDay()]+". Current time is : "+(current_date.getHours())%12+" "+mode[parseInt(current_date.getHours()/12)]+" : "+current_date.getMinutes()+" : "+current_date.getSeconds();
	document.write(res);
	</script>
	</body>
</html>
Output

Today is: Thursday. Current time is : 10 PM : 14 : 31

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz