Sunday, April 18, 2021

8. Write a JavaScript program to get the current date.

8. Write a JavaScript program to get the current date.

<script>

var today = new Date();
var dd = today.getDate();

var mm = today.getMonth()+1; 
var yyyy = today.getFullYear();

if(dd<10) 
{
    dd='0'+dd;

if(mm<10) 
{
    mm='0'+mm;

today = mm+'-'+dd+'-'+yyyy;
console.log(today);

today = mm+'/'+dd+'/'+yyyy;
console.log(today);

today = dd+'-'+mm+'-'+yyyy;
console.log(today);

today = dd+'/'+mm+'/'+yyyy;
console.log(today);

</script>

No comments: