ntp 包提供了一種從網路時間協定(NTP)伺服器取得準確系統時間的簡單方式。它讓應用程式能夠取得與全球時間標準同步的精確 DateTime 值,這在日誌記錄、排程或跨裝置同步等對時間敏感的操作中特別有用。該包支援 Android、iOS、macOS、Windows 和 Linux 等多個平台,確保在不同環境中的行為一致。它使用標準 NTP 協定,並提供易於使用的 API 來取得目前時間,而不需依賴本機裝置時鐘。
適用情境
同步應用時間戳與全球時間
提高基於時間的日誌記錄的準確性
啟用可靠的任務排程
驗證設備時鐘漂移
支援需要精確時間的分散式系統
主要特色
從 NTP 伺服器取得即時資料
跨平台相容性
簡單的同步與非同步 API
高精度時間取得
最小依賴
適合對象
需要高精度時間的應用程式
時間敏感的服務
物聯網和後端系統
需要同步時鐘的行動和桌面應用程式
時間驗證的開發工具
使用建議
需要網路連接才能使用
可能因網路狀況而產生延遲
不適用於離線使用
伺服器可用性影響可靠性
時區處理必須另行管理
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
NTP
Plugin that allows you to get precise time from Network Time Protocol (NTP).
It implements whole NTP protocol in dart.
This is useful for time-based events since DateTime.now() returns the time of the device.
Users sometimes change their internal clock and using DateTime.now() can give
wrong result. You can just get clock offset [NTP.getNtpTime] and apply it manually
to DateTime.now() object when needed (just add offset as milliseconds duration), or you can get
already formatted [DateTime] object from [NTP.now].
By default lookup address for NTP is: time.google.com
For example on how to use look in github library repository example/ folder.