Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

137
Views
How to get current date and time of user laptop not server in angular?

I have deployed the angular app on the server, but I want to get my system (laptop) date and time in the application.
Suppose the server has the date and time of timeZoneA while my laptop has date and time of TimeZoneB, so basically, I want that timeZoneB should be shown in the application opened in the browser of my laptop.

this.currentDateTime = new Date();

I can get date and time of any specific zone. but it's not requirement.

formatDate(new Date(),'dd-MM-yyyy hh:mm:ss a','en-US','+0500');
10 months ago · Santiago Trujillo
1 answers
Answer question

0

In the question you are passing the timezone in formatDate so that is why you are getting the specific timezone date.

Remove the timezone from formatDate to the local date and time.

change :

formatDate(new Date(), 'dd-MM-yyyy hh:mm:ss a','en-US','+0500');

to :

date = formatDate(new Date(), 'dd-MM-yyyy hh:mm:ss a', 'en-US');

If you want to get the time of specific time zone :

function getTime(){
    //timeZone can be  "CST","GMT" ,"Asia/Jerusalem" , etc
    var d = new Date(new Date().toLocaleString("en-US", {timeZone: "CST"}));
    var n = d.toLocaleString(); // just to get date & time
    return n;
}
10 months ago · Santiago Trujillo Report
Answer question
Find remote jobs