패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.0

ntp

(NTP) 네트워크 시간 프로토콜 서버에서 정확한 시간 또는 현재의 DateTime 객체를 가져옵니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
17.7만
좋아요
261
Pub 점수
150

패키지 설치

flutter pub add ntp

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

ntp 패키지는 네트워크 시간 프로토콜(NTP) 서버에서 정확한 시스템 시간을 가져오는 간단한 방법을 제공합니다. 애플리케이션은 글로벌 시간 기준과 동기화된 정밀한 DateTime 값을 얻을 수 있으며, 로깅, 스케줄링 또는 장치 간 동기화와 같은 시간에 민감한 작업에 특히 유용합니다. 이 패키지는 Android, iOS, macOS, Windows 및 Linux 등 여러 플랫폼을 지원하여 환경 간 일관된 동작을 보장합니다. 표준 NTP 프로토콜을 사용하며, 로컬 장치의 시계에 의존하지 않고 현재 시간을 얻는 데 용이한 API를 제공합니다.

사용 사례

  • 앱 타임스탬프를 글로벌 시간과 동기화
  • 시간 기반 로깅의 정확도 향상
  • 신뢰할 수 있는 작업 스케줄링 활성화
  • 장치 시계 왜곡 검증
  • 정밀한 타이밍을 필요로 하는 분산 시스템 지원

주요 기능

  • NTP 서버에서 실시간 데이터를 가져옵니다
  • 크로스 플랫폼 호환성
  • 간단한 동기 및 비동기 API
  • 고정밀 시간 검색
  • 최소 종속성

적합한 대상

  • 고정밀 시간이 필요한 응용 프로그램
  • 시간에 민감한 서비스
  • 사물인터넷 및 백엔드 시스템
  • 동기화된 시계가 필요한 모바일 및 데스크톱 앱
  • 시간 검증을 위한 개발 도구

고려 사항

  • 기능을 사용하려면 인터넷 연결이 필요합니다
  • 네트워크 상태에 따라 지연이 발생할 수 있습니다
  • 오프라인 사용에 적합하지 않습니다
  • 서버 가용성은 신뢰성에 영향을 미칩니다
  • 시간대 처리는 별도로 관리되어야 합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

pub package CodeFactor

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.

How it works

Using int offset from getNtpTime()

  • default localTime is DateTime.now()
  • default lookUpAddress is 'time.google.com'
  • default port is 123
  DateTime startDate = new DateTime.now().toLocal();
  int offset = await NTP.getNtpOffset(localTime: startDate);
  print('NTP DateTime offset align: ${startDate.add(new Duration(milliseconds: offset))}');

Using DateTime from now

  DateTime startDate = await NTP.now();
  print('NTP DateTime: ${startDate}');
NTP Functions
  Future<int> getNtpOffset({
    String lookUpAddress: 'time.google.com',
    int port: 123,
    DateTime localTime,
    Duration timeout,
  });
  Future<DateTime> now();

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트