gmt 0.8.0 copy "gmt: ^0.8.0" to clipboard
gmt: ^0.8.0 copied to clipboard

Get current datetime in GMT from internet (example.com, google.com or your own urls) and return DateTime in UTC.

GMT #

Get current datetime in GMT from internet (example.com, google.com or your own urls) and return DateTime in UTC.

This package provides an easy way to get the current DateTime in UTC from the internet. It will get DateTime from the headers of the URLs. On web platform, the package will use headers from current URL to avoid CORS error.

You can also use this package to check if there is real internet connection.

Usage:

var now = await GMT.now();

You can create your own list of URLs and timout of each URL:

var now = GMT.now(
    urls: ['https://www.your-server.com'],
    timeoutOfEach: const Duration(seconds: 1),
    );

If you want to get local DateTime if it gives error or timeout then using (default is return null):

var now = await GMT.now(returnLocalIfError: true); // Default is false

You can also set a timeout for this whole function by using:

var now = await GMT.now(timeout: const Duration(seconds: 5));

Default URLs:

  • 1.1.1.1
  • 1.0.0.1
  • 8.8.8.8
  • 8.8.4.4
  • example.com
1
likes
160
points
225
downloads

Publisher

verified publisherlamnhan.dev

Weekly Downloads

Get current datetime in GMT from internet (example.com, google.com or your own urls) and return DateTime in UTC.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, universal_io

More

Packages that depend on gmt