English, asked by RoyalBoy007, 1 year ago

experts you cant solve a singel question of mine what kind of experts are you.
plz solve my question
Write a javascript program to display

* * * * *

* * * *

* * *

* *

*


surjit55: I'm in 10th ..
RoyalBoy007: area you on social media
surjit55: nope
RoyalBoy007: ok
RoyalBoy007: where are you from
surjit55: I'm from punjab.. and u ??!!
RoyalBoy007: maharashtra
RoyalBoy007: most f the girls from punjab are not on social media
surjit55: Hehe... XD. .
RoyalBoy007: what is mean by XD

Answers

Answered by ashishbarwar586
0

w3resource

menu

Custom Search

share

JavaScript Exercises

JavaScript: Display the current day and time in a specific format

Last update on February 09 2019 08:36:03 (UTC/GMT +8 hours)

JavaScript Basic: Exercise-1 with Solution

Write a JavaScript program to display the current day and time in the following format.

Today is : Tuesday.

Current time is : 10 PM : 30 : 38

Pictorial Presentation:

JavaScript: Display the current day and time in a specific format

Sample Solution:

HTML Code:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>JavaScript current day and time</title>

</head>

<body></body>

</html>

Copy

JavaScript Code:

var today = new Date();

var day = today.getDay();

var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];

console.log("Today is : " + daylist[day] + ".");

var hour = today.getHours();

var minute = today.getMinutes();

var second = today.getSeconds();

var prepand = (hour >= 12)? " PM ":" AM ";

hour = (hour >= 12)? hour - 12: hour;

if (hour===0 && prepand===' PM ')

{

if (minute===0 && second===0)

{

hour=12;

prepand=' Noon';

}

else

{

hour=12;

prepand=' PM';

}

}

if (hour===0 && prepand===' AM ')

{

if (minute===0 && second===0)

{

hour=12;

prepand=' Midnight';

}

else

{

hour=12;

prepand=' AM';

}

}

console.log("Current Time : "+hour + prepand + " : " + minute + " : " + second);

Copy

Sample Output:

Today is : Tuesday.

Current Time : 10 PM : 30 : 38

Explanations:

Declaring a JavaScript date : In JavaScript Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC. You can declare a date in the following ways :

Similar questions