简体   繁体   中英

How to pass TimeZone Name from Angular to .NET API?

I have an API that accepts the TimeZone name (America/Denver) as a string. In the Angular UI application, I am passing the TimeZone name by detecting the browser timeZoneName. But when the API receives the string as America/Denver it considers as a route parameter and doesn't work as expected.

So, I am replacing the / with - in Angular using string.replace() and passing to the API, and converting it back in .NET API.

I think it is a bad practice to modify timeZone names. Can anyone advise on how to pass timeZone names from Angular to .NET API?

Is it possible to pass the offsets from the UI and get timeZone names in API?

You would need to encode the string parameter you are sending to the api.

Do something like:

let timeZone  = "America/Denver"

let encodedTimeZone = encodeURIComponent(timeZone);

and send the encodedTimeZone to the api. You can log the encodedTimeZone to the console to see the encoded string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM