Skip to main content

DateTimeFormatsVN

The DateTimeFormatsVN class defines a set of standardized date and time formats tailored for the Vietnamese locale (vi_VN). These constants are designed to work seamlessly with the intl package and ensure consistent formatting across your app.


🧠 Why use this?​

  • Enforces locale-specific formatting.
  • Centralizes all date/time format strings in one place.
  • Improves consistency, reusability, and maintainability.

πŸ“¦ Usage​

import 'package:intl/intl.dart';

final formatted = DateFormat(DateTimeFormatsVN.dateOnly, 'vi_VN').format(DateTime.now());
print(formatted); // e.g., 26/03/2025

πŸ“‹ Available Formats​

ConstantFormat StringExample
dateTimedd/MM/yyyy HH:mm:ss01/01/2024 14:30:45
dateTimeWithoutSecondsdd/MM/yyyy HH:mm01/01/2024 14:30
dateOnlydd/MM/yyyy01/01/2024
timeOnlyHH:mm:ss14:30:45
timeOnlyWithoutSecondsHH:mm14:30
dateWithDayAndMonthOnlydd/MM01/01
yearOnlyyyyy2024
dateWithDayNameEEEE, dd/MM/yyyyThα»© Hai, 01/01/2024
dateWithMonthNamedd MMMM yyyy01 ThΓ‘ng Mα»™t 2024
shortDateWithMonthNamedd MMM01 ThΓ‘ng Mα»™t

βœ… Best Practices​

  • Use these constants throughout your app to avoid hardcoding format strings.
  • Always pass "vi_VN" explicitly to the DateFormat constructor to ensure proper localization.
  • Use DateFormat(...).format(...) instead of .toString() for user-facing strings.

πŸ“‚ Location​

This class is defined in:
lib/constants/constants.dart

It is marked with part of "constants.dart";, so ensure your constants.dart file includes:

part 'date_time_formats_vn.dart';