srawlins / timezone

Time zone database and time zone aware DateTime object for Dart.
BSD 2-Clause "Simplified" License
102 stars 54 forks source link

how to get current local timezone on web? #67

Closed PhloxDev closed 3 years ago

PhloxDev commented 4 years ago

I want to get current timezone name like Europe/london. how to get it?

srawlins commented 3 years ago

@PhloxDev there is documentation in README.md. Specifically this section shows an example of getting a time zone by name: https://github.com/srawlins/timezone#initialization-for-browser-environment.

scopendo commented 3 years ago

I don't think this question has been answered. It's clear how to get the time zone object for an IANA time zone id such as America/Detroit, but the question appears to be asking how to get the time zone id itself in a web environment.

enyo commented 3 years ago

So I've looked around, and I don't think there is a way to get it with this library. If you're on web, then you need to use the ECMAScript Internationalization API. I don't think that there is a dart implementation for it, but you can simply write your JavaScript interop code for it.

If you're using flutter, then the package flutter_native_timezone can expose it for you, and it now supports web as well.