搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.0

age_calculator

一個用於計算某人年齡(以天、月、年為單位)的 Flutter 套件;此外,還可用於計算兩個日期之間的差異。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
66
Pub 分數
160

安裝套件

flutter pub add age_calculator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

age_calculator 套件是一個專為 Flutter 設計的實用工具,用於計算一個人的年齡(以年、月、日表示)。它還允許使用者精確計算兩個日期之間的差異。適用於需要年齡驗證或日期比較的應用程式,例如健康應用、註冊表單或活動規劃工具。該套件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,確保跨平台的一致性。它為開發者提供了一個簡單直覺的 API,可輕鬆將年齡計算功能整合到其應用程式中。

適用情境

  • 使用者註冊中的年齡驗證
  • 在醫療應用程式中計算患者年齡
  • 根據年齡確定事件資格
  • 用於排程目的的日期比較
  • 使用日期差值追蹤里程碑

主要特色

  • 計算年齡(以年、月、日為單位)
  • 精確計算日期差異
  • 跨平台相容性
  • 簡單直覺的 API
  • 支援空值安全的日期輸入

適合對象

  • 表單驗證需要年齡檢查
  • 健康與保健應用
  • 生日和紀念日追蹤器
  • 基於時間的學習教育應用
  • 需要精確日期計算的應用程式

使用建議

  • 需要有效的 DateTime 輸入
  • 可能需要處理閏年等邊緣情況
  • 未針對非常大的日期範圍進行優化
  • 僅限基於日期的計算
  • 不包含時區感知功能

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

age_calculator

A Flutter package that allows you to perform operations between dates:

  • Calculate a person's age and the time remaining to their next birthday in years, months and days.
  • Calculate differences between two dates in years, months and days.
  • Add years, months and days to any date.

Getting Started

In your flutter project add the dependency:

dependencies: ... age_calculator: ^1.0.0

For help getting started with Flutter, view the online documentation.

Example
import 'package:age_calculator/age_calculator.dart';

void main() {
  DateTime birthday = DateTime(1997, 3, 5);

  DateDuration duration;

  // Find out your age as of today's date 2021-03-08
  duration = AgeCalculator.age(birthday);
  print('Your age is $duration'); // Your age is Years: 24, Months: 0, Days: 3

  //Find out your age on any given date
  duration = AgeCalculator.age(birthday, today: DateTime(2030, 5, 1));
  print('Your age is $duration'); // Your age is Years: 33, Months: 1, Days: 26

  // Find out when your next birthday will be at 2021-03-08
  duration = AgeCalculator.timeToNextBirthday(birthday);
  print('You next birthday will be in $duration');
  // You next birthday will be in Years: 0, Months: 11, Days: 25

  // Find out when your next birthday will be on any given date
  duration = AgeCalculator.timeToNextBirthday(birthday,
      fromDate: DateTime(2021, 3, 2));
  print('You next birthday will be in $duration');
  // You next birthday will be in Years: 0, Months: 0, Days: 3

  // Find out the difference between two dates
  duration = AgeCalculator.dateDifference(
    fromDate: DateTime(2021, 1, 2),
    toDate: DateTime(2025, 5, 2),
  );
  print('The difference is $duration');
  // You next birthday will be in Years: 4, Months: 4, Days: 0

  // Add time to any date
  DateTime date = AgeCalculator.add(
      date: DateTime(2021, 1, 2),
      duration: DateDuration(years: 5, months: 2, days: 1));
  print(date);
  // 2026-03-03 00:00:00.000
}

所屬分類

原始碼儲存庫

使用此套件的專案