date_manager 0.0.4 copy "date_manager: ^0.0.4" to clipboard
date_manager: ^0.0.4 copied to clipboard

A simple and easy-to-use date formatting and relative time utility for Flutter and Dart.

example/lib/main.dart

import 'package:date_manager/date_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    DateTime now = DateTime.now();

    return MaterialApp(
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      home: Scaffold(
        appBar: AppBar(title: const Text("DateManager Example")),
        body: Padding(
          padding: const EdgeInsets.all(20.0),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('Current DateTime: $now'),
                const SizedBox(height: 10),

                // Numeric Formats
                Text(
                  'Numeric Formats:',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'shortDate: ${DateManager.format(now, DateManager.shortDate)}',
                ),
                Text(
                  'shortDate2Digit: ${DateManager.format(now, DateManager.shortDate2Digit)}',
                ),
                Text(
                  'shortDateUS: ${DateManager.format(now, DateManager.shortDateUS)}',
                ),
                Text(
                  'shortDateUS2Digit: ${DateManager.format(now, DateManager.shortDateUS2Digit)}',
                ),
                Text(
                  'isoDate: ${DateManager.format(now, DateManager.isoDate)}',
                ),
                Text(
                  'isoDateSlash: ${DateManager.format(now, DateManager.isoDateSlash)}',
                ),
                Text(
                  'shortDateDash: ${DateManager.format(now, DateManager.shortDateDash)}',
                ),
                Text(
                  'shortDateDashUS: ${DateManager.format(now, DateManager.shortDateDashUS)}',
                ),
                const SizedBox(height: 10),

                // Textual Formats
                Text(
                  'Textual Formats:',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'longDate: ${DateManager.format(now, DateManager.longDate)}',
                ),
                Text(
                  'longDateUS: ${DateManager.format(now, DateManager.longDateUS)}',
                ),
                Text(
                  'longDateAbbr: ${DateManager.format(now, DateManager.longDateAbbr)}',
                ),
                Text(
                  'longDateAbbrUS: ${DateManager.format(now, DateManager.longDateAbbrUS)}',
                ),
                Text(
                  'fullDate(Locale - fr): ${DateManager.format(now, DateManager.fullDate, locale: 'fr')}',
                ),

                Text(
                  'dayMonthAbbr(Locale - bn): ${DateManager.format(now, DateManager.dayMonthAbbr, locale: 'bn')}',
                ),

                const SizedBox(height: 10),

                // Time Formats
                Text(
                  'Time Formats:',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'shortTime24: ${DateManager.format(now, DateManager.shortTime24)}',
                ),
                Text(
                  'shortTime12: ${DateManager.format(now, DateManager.shortTime12)}',
                ),
                Text(
                  'longTime24: ${DateManager.format(now, DateManager.longTime24)}',
                ),
                Text(
                  'longTime12: ${DateManager.format(now, DateManager.longTime12)}',
                ),
                const SizedBox(height: 10),

                // Date + Time Formats
                Text(
                  'Date + Time Formats:',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'dateTime24: ${DateManager.format(now, DateManager.dateTime24)}',
                ),
                Text(
                  'dateTime12: ${DateManager.format(now, DateManager.dateTime12)}',
                ),
                Text(
                  'dateTime24Dash: ${DateManager.format(now, DateManager.dateTime24Dash)}',
                ),
                Text(
                  'dateTime12Dash: ${DateManager.format(now, DateManager.dateTime12Dash)}',
                ),
                Text(
                  'shortDateTime24US: ${DateManager.format(now, DateManager.shortDateTime24US)}',
                ),
                Text(
                  'shortDateTime12USDash: ${DateManager.format(now, DateManager.shortDateTime12USDash)}',
                ),
                Text(
                  'isoDateTimeUtc: ${DateManager.format(now, DateManager.isoDateTimeUtc)}',
                ),
                Text(
                  'isoDateTimeWithOffset: ${DateManager.format(now, DateManager.isoDateTimeWithOffset)}',
                ),
                const SizedBox(height: 10),

                // Relative Time
                Text(
                  'Relative Time:',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'Time ago: ${DateManager.timeAgo(now.subtract(const Duration(days: 1)))}',
                ),
                Text(
                  'Time later: ${DateManager.timeLater(now.add(const Duration(hours: 5)))}',
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
160
points
50
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A simple and easy-to-use date formatting and relative time utility for Flutter and Dart.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, intl

More

Packages that depend on date_manager