Utilities
The Date Adapter is an abstraction layer that allows components to use date objects from any date library, ensuring compatibility and easy integration.
Import the DateAdapter from ng-primitives/date-time
.
Angular Primitives ships with two date adapters out of the box: NgpNativeDateAdapter
and NgpLuxonDateAdapter
.
The NgpNativeDateAdapter
uses the native JavaScript Date
object, while the NgpLuxonDateAdapter
uses the Luxon date library.
To use a date adapter, you need to provide it to Angular's dependency injection system. This can be done once at the root of your application or at a component/module level.
If no date adapter is provided, the NgpNativeDateAdapter
will be used by default.
Should you need to use a different date library, you can create your own date adapter by implementing the NgpDateAdapter
interface.
Should you wish to use the adapter in a component, you can inject it into a component.
All date adapters must implement the NgpDateAdapter
interface.
Copyright © 2025 Angular Primitives