0

I'm currently getting the time in my client using Angular 11 (TypeScript).

I have noticed that actually, each user(using my website) can have a different hour , according to his\her location.

I'm using the follwoing code to get the current time:

let todaysDate = new Date().getTime();

If I'll open the website in Israel I'll get the local time, but opening the website in Australia will provide a different time.

I have a logic that rests on time comparison.

Do I have an option to get the specific area time(Israel for instance) for all users beside getting the time from server? I want to keep this logic only in my client side.

JumpIntoTheWater
  • 1,306
  • 2
  • 19
  • 46
  • Hi Yaniv. I think this post may help you: https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone/15171030#15171030 (Matt Johnson-Pint answer) – monogate Dec 01 '20 at 09:15
  • What are the semantics of your comparison? Do you need to compare two local times? For instance `15:30` in Jerusalem localtime and `15:30` in Canberra localtime to be equal. Or Do you need `15:30` in Israel (ie 13:30UTC) to be later than `15:30` in Canberra (ie 4:30UTC)? – derpirscher Dec 01 '20 at 09:26
  • @monogate thanks. @derpirscher no. actually I have a static time data which I compare to. The real example is that I reveal a button only if the the `current_time>=static_time` – JumpIntoTheWater Dec 01 '20 at 10:16

1 Answers1

0

Convert date to a specific timezone using below code

to = new DatePipe('en-Us').transform(this.today, 'dd:MM:yyyy hh-mm-ss', 'GMT+1');

Refer Answer

Gokul Prasannan
  • 318
  • 1
  • 4
  • the thing is that I can't make to compare I wish for since I get an error says : `operator >= can't be applied to types string and number` – JumpIntoTheWater Dec 01 '20 at 13:12