pretty_date_time 0.0.3 copy "pretty_date_time: ^0.0.3" to clipboard
pretty_date_time: ^0.0.3 copied to clipboard

A Dart utility package to convert DateTime objects into human-friendly strings like "5 minutes ago", "Yesterday", or "in 2 days".

🕒 Pretty Date Time

Convert DateTime into human-friendly readable strings like “Just now”, “Yesterday”, “in 3 days”, etc.

📦 Installation #

Add the following to your pubspec.yaml file:

dependencies:
  pretty_date_time: ^0.0.3

Then run:

flutter pub get

🚀 Getting Started #

Import the package in your Dart file:

import 'package:pretty_date_time/pretty_date_time.dart';

🕒 Basic Example #

final now = DateTime.now();
print(prettyDateTime(now.subtract(Duration(minutes: 5)))); 
// Output: "5 minutes ago"

print(prettyDateTime(now.add(Duration(hours: 3)))); 
// Output: "in 3 hours"

⏰ With Custom Reference Time #

final reference = DateTime(2024, 01, 01, 12, 0, 0);
final target = DateTime(2024, 01, 01, 11, 50, 0);

print(prettyDateTime(target, reference: reference));
// Output: "10 minutes ago"

✅ Features #

Supports past and future DateTime values

Pure Dart implementation

Zero dependencies

Works on Flutter and Dart CLI projects

💡 Contribution #

Pull requests and issues are welcome! If you find a bug or want a feature, feel free to open an issue or contribute.

6
likes
140
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart utility package to convert DateTime objects into human-friendly strings like "5 minutes ago", "Yesterday", or "in 2 days".

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on pretty_date_time