date_util_plus 0.0.1 date_util_plus: ^0.0.1 copied to clipboard
A simple dart API with a complete set of date helper methods not available in the DateTime API.
Installation #
Date Util Plus #
Say goodbye to date-related headaches with a complete set of date helper methods that go beyond the DateTime API.
Key Features #
- Date Formatting: Format dates with precision using a variety of format options.
- Age Calculation: Effortlessly calculate ages based on birthdates and the current date.
- Date Manipulation: Add or subtract days, months, years, hours, minutes, or seconds from date objects.
- Weekday Handling: Seamlessly handle weekdays, skipping weekends when necessary.
- String-to-Date Detection: Automatically detect date formats from strings, simplifying date parsing.
- Easy Integration: Quickly integrate Date Utils Plus into your Dart and Flutter projects for enhanced date and time functionality.
Installation #
To use Date Utils Plus in your Dart or Flutter project, add it as a dependency in your pubspec.yaml
file:
dependencies:
date_utils_plus: ^0.0.1 # Use the latest version
Run flutter pub get to fetch the package.
Import the necessary package in your Dart file:
import 'package:date_util_plus/date_util.dart';
Usage #
DateTime Formatting #
- Format DateTime as ISO 8601
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
String iso8601 = myDateTime.toIso8601();
print('ISO 8601 Format: $iso8601'); // ISO 8601 Format: 2023-09-23T14:30:00.000
- Format DateTime as Short Date (MM/DD/YYYY)
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
String shortDate = myDateTime.toShortDate();
print('Short Date: $shortDate'); // Short Date: 09/23/2023
- Format DateTime as Long Date (Month DD, YYYY)
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
String longDate = myDateTime.toLongDate();
print('Long Date: $longDate'); // Long Date: September 23, 2023
- Format DateTime as 24-Hour Time (HH:MM:SS)
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
String time24Hour = myDateTime.to24HourTime();
print('24-Hour Time: $time24Hour'); // 24-Hour Time: 14:30:00 // Long Date: September 23, 2023
- Format DateTime as 12-Hour Time with AM/PM (hh:MM:SS AM/PM)
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
String time12Hour = myDateTime.to12HourTime();
print('12-Hour Time: $time12Hour'); // 12-Hour Time: 02:30:00 PM
- Calculate Age
DateTime birthDate = DateTime(1990, 5, 15);
int age = birthDate.calculateAge;
print('Age: $age years'); // Age: 33 years
- Adding and Subtracting Time
DateTime myDateTime = DateTime(2023, 9, 23, 14, 30);
DateTime futureDate = myDateTime.addDays(5);
DateTime pastDate = myDateTime.subtractDays(2);
- Weeks in Month
DateTime myDateTime = DateTime(2023, 9, 23);
int weeksInMonth = myDateTime.weeksInMonth();
print('Weeks in Month: $weeksInMonth'); // Weeks in Month: 4
- Detect Date format from String
String? dateFormat = "September 23, 2023".detectDateFormat();
print(dateFormat); // MMMM dd, yyyy
- Format date with reference
String? formattedDate = DateTime.now().formatDate(likeGiven: "September 23, 2023");
print(formattedDate); //September 24, 2023
Feature requests and Bug reports #
Feel free to post a feature requests or report a bug here.