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>
▶ RUN

Output/ Explanation:

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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad