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');
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;
}