1.

How to create a Boolean object using JavaScript?

Answer»

The Date() method is to be USED in JavaScript to GET today’s date and time.

The following is the syntax:

Date()

Let us see the example to display the current date and time: 

<!DOCTYPE HTML> <html> <body> <script> var date = Date(); document.write("Date and Time = " + date ); </script> </body> </html>

The output displays today’s date and time:

Date and Time = Fri Dec 14 2018 20:16:22 GMT+0530 (India STANDARD Time)

Let’s say you need to only fetch the time portion of the date. For that, use the toTimeString() method:

<!DOCTYPE html> <html> <body> <script>    var date = new Date(2018, 12, 14, 10, 11, 30);    document.write( date.toTimeString() ); </script> </body> </html>

The output displays only the current time: 

10:11:30 GMT+0530 (India Standard Time)


Discussion

No Comment Found