date_format 1.0.4

date_format #

A simple API to format dates.

Usage #

Use formatDate function to format a DateTime

print(formatDate(new DateTime(1989, 02, 21), [yyyy, '-', mm, '-', dd]));

Output:

1989-02-21

Long month names #

print(formatDate(new DateTime(1989, 2, 21), [yy, '-', M, '-', d]));

Output:

89-feb-21

Time parts #

print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss]));

Output:

15:40:10

Timezone #

print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss, z]));

Output:

15:40:10+0100

Changelog #

1.0.4 #

  • Capital letters

1.0.2 #

  • Fixed negative timezone bug

1.0.1 #

  • Docs
  • Added microsecond

1.0.0 #

  • formatDate

example/date_format_example.dart

import 'package:date_format/date_format.dart';

main() {
  print(formatDate(new DateTime(1989, 2, 21), [yyyy, '-', mm, '-', dd]));
  print(formatDate(new DateTime(1989, 2, 21), [yy, '-', m, '-', dd]));
  print(formatDate(new DateTime(1989, 2, 1), [yy, '-', m, '-', d]));

  print(formatDate(new DateTime(1989, 2, 1), [yy, '-', MM, '-', d]));
  print(formatDate(new DateTime(1989, 2, 21), [yy, '-', M, '-', d]));

  print(formatDate(new DateTime(1989, 2, 1), [yy, '-', M, '-', d]));

  print(formatDate(new DateTime(2018, 1, 14), [yy, '-', M, '-', DD]));
  print(formatDate(new DateTime(2018, 1, 14), [yy, '-', M, '-', D]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [hh, ':', nn, ':', ss, ' ', am]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [hh, ':', nn, ':', ss, ' ', am]));

  print(formatDate(new DateTime(1989, 02, 1, 15, 40, 10), [hh]));
  print(formatDate(new DateTime(1989, 02, 1, 15, 40, 10), [h]));

  print(formatDate(new DateTime(1989, 02, 1, 5), [am]));
  print(formatDate(new DateTime(1989, 02, 1, 15), [am]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss, z]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss, ' ', Z]));

  print(formatDate(new DateTime(1989, 02, 21), [yy, ' ', w]));
  print(formatDate(new DateTime(1989, 02, 21), [yy, ' ', W]));

  print(formatDate(new DateTime(1989, 12, 31), [yy, '-W', W]));
  print(formatDate(new DateTime(1989, 1, 1), [yy, '-', mm, '-w', W]));

  print(formatDate(
      new DateTime(1989, 02, 1, 15, 40, 10), [HH, ':', nn, ':', ss, ' ', Z]));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  date_format: ^1.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:date_format/date_format.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
98
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0

Admin