Aniket Narvankar

Aniket Narvankar

  • 558
  • 2.1k
  • 608k

Get Current Time from Server Side in Javascript

Jul 12 2022 10:05 AM

 function getCurrentDateTime() {
        var currentDate = new Date();
        var currentYear = currentDate.getFullYear();
        var currentMonth = currentDate.getMonth() + 1;
        var currentDay = currentDate.getDate();
        if (currentDay < 10) currentDay = '0' + currentDay;
        if (currentMonth < 10) currentMonth = '0' + currentMonth;
        var todayDate = currentMonth + '/' + currentDay + '/' + currentYear;
        return todayDate;
    }

 

I have written the following method to fetch current time in javascript. but this is giving me browser time,i want server time. how to get server side time in javascript,please do let me know about the same. stuck on this.


Answers (5)