@danielmoncada/angular-datetime-picker

中文文档
22.0.0发布于 2026/08/05MITTypeScriptES Module近 30 天下载 22.6万

Angular Date Time Picker

原始使用文档
文档目录16 节
  1. Breaking Changes
  2. Description
  3. How to Use
  4. Choose a date implementation
  5. Properties for owl-date-time
  6. Events for owl-date-time
  7. Properties for input[owlDateTime]
  8. Events for input[owlDateTime]
  9. Properties for [owlDateTimeTrigger]
  10. Properties for [owlDateTimeTrigger]
  11. Properties for owl-date-time-inline
  12. Localization and DateTime Format
  13. Dependencies
  14. Demo
  15. License
  16. Author

:date: :clock1: Angular Date/Time Picker

npm npm

The current version of this package supports Angular 22

If you need support for other Angular version, see Breaking Changes below.

Breaking Changes

  • Version 22.x.x is the official release for Angular 22 and it also supports Angular 21.
  • Version 21.x.x is the official release for Angular 21 and it also supports Angular 20.
  • Version 20.x.x is the official release for Angular 20 and it also supports Angular 19.
  • Version 19.x.x >= no longer supports ng 18. If you need ng 18 support, stick with version 18.x.x.
  • Version 18.x.x >= no longer supports ng 17. If you need ng 17 support, stick with version 17.x.x.
  • Version 17.x.x >= no longer supports ng 16 - 13. If you need ng 16-13 support, stick with version 16.x.x.
  • Version 14.x.x >= no longer supports < ng 13. If you need View Engine support, stick with version 13.x.x.
  • Version 13.1.0+ no longer supports the MomentJs time adapter natively. If you want to use the MomentJs adapter, see GitHub or npm.
  • If you need ng 8 support, please stick with: https://github.com/DanielYKPan/date-time-picker

Description

Simple Angular date time picker. Online doc is here, Online demos(StackBlitz) are here and here. This picker is responsive design, so feel free to try it in your desktops, tablets and mobile devices.

How to Use

  1. Install with npm: npm install @danielmoncada/angular-datetime-picker --save

  2. Install @angular/cdk, which is a peer dependency and provides the overlay used by the picker: npm install @angular/cdk --save. If your app already uses Angular Material, the CDK is installed for you and this step (and the overlay styles below) is already covered.

  3. Add styles. The picker renders its popup/dialog inside a CDK overlay, so you need both the picker styles and the CDK's prebuilt overlay styles. If you are not using Angular Material, add them once — either in your styles.scss:

    @use '@angular/cdk/overlay-prebuilt.css';
    @use '@danielmoncada/angular-datetime-picker/assets/style/picker.min.css';
    

    or via the styles array in angular.json:

    "styles": [
        "node_modules/@angular/cdk/overlay-prebuilt.css",
        "node_modules/@danielmoncada/angular-datetime-picker/assets/style/picker.min.css",
        "src/styles.scss"
    ]
    

    (If you already import Angular Material's theme, the CDK overlay styles are included and you only need the picker styles.)

  4. Add OwlDateTimeModule and OwlNativeDateTimeModule to your @NgModule like example below

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { MyTestApp } from './my-test-app';
    import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';
    
    @NgModule({
        imports: [BrowserModule, OwlDateTimeModule, OwlNativeDateTimeModule],
        declarations: [MyTestApp],
        bootstrap: [MyTestApp],
    })
    export class MyTestAppModule {}
    
  5. Connecting a picker to an input and a trigger.

    <input [owlDateTime]="dt1" [owlDateTimeTrigger]="dt1" placeholder="Date Time" /> <owl-date-time #dt1></owl-date-time>
    
    <input [owlDateTime]="dt2" placeholder="Date Time" />
    <span [owlDateTimeTrigger]="dt2"><i class="fa fa-calendar"></i></span>
    <owl-date-time #dt2></owl-date-time>
    

    The examples above are quite basic. The picker has much more features, and you could learn more about those from demo page.

Choose a date implementation

The date-time picker was built to be date implementation agnostic. Developers need to make sure to provide the appropriate pieces for the picker to work with their chosen implementation. There are two pre-made modules, users need to import one of them or build your own one (learn more about this from here).

  • OwlNativeDateTimeModule - support for native JavaScript Date object
  • OwlUnixTimestampDateTimeModule - support for milliseconds since Epoch (number)
Date/Time Adapter Extensions

https://day.js.org/

  • OwlDayJsDateTimeModule - support for DayJs
    • You must install an optional adapater to use this. see here, npm

https://momentjs.com/

  • OwlMomentDateTimeModule - support for MomentJs
    • You must install an optional adapater to use this. see here, npm

Properties for owl-date-time

NameTypeRequiredDefaultDescription
pickerTypeboth, calendar, timerOptionalbothSet the type of the dateTime picker. both: show both calendar and timer, calendar: only show calendar, timer: only show timer.
pickerModepopup, dialogOptionalpopupThe style the picker would open as.
startViewmonth, year, multi-yearOptionalmonthThe view that the calendar should start in.
yearOnlybooleanOptionalfalseRestricts the calendar to only show the year and multi-year views for month selection.
showCalendarWeeksbooleanOptionalfalseWhether to show calendar weeks in the calendar.
multiyearOnlybooleanOptionalfalseRestricts the calendar to only show the multi-year view for year selection.
startAtT/nullOptionalnullThe moment to open the picker to initially.
endAtT/nullOptionalnullThe the default selected time for range calendar end time
firstDayOfWeeknumberOptional0Set the first day of week. Valid value is from 0 to 6. 0: Sunday - 6: Saturday
showSecondsTimerbooleanOptionalfalseWhen specify it to true, it would show a timer to configure the second's value
hideOtherMonthsbooleanOptionalfalseWhether to hide dates in other months at the start or end of the current month
hour12TimerbooleanOptionalfalseWhen specify it to true, the timer would be in hour12 format mode
stepHournumberOptional1Hours to change per step.
stepMinutenumberOptional1Minutes to change per step.
stepSecondnumberOptional1Seconds to change per step.
scrollStrategyScrollStrategyOptionalBlockScrollStrategyDefine the scroll strategy when the picker is open. Learn more this from https://material.angular.io/cdk/overlay/overview#scroll-strategies.
disabledbooleanOptionalfalseWhen specify to true, it would disable the picker.
backdropClassstring/string[]OptionalnullCustom class for the picker backdrop.
panelClassstring/string[]OptionalnullCustom class for the picker overlay panel.

Events for owl-date-time

EventsParameterDescription
beforePickerOpennullCallback to invoke before the picker is opened
afterPickerOpennullCallback to invoke when the picker is opened
afterPickerClosednullCallback to invoke when the picker is closed.
yearSelectedTCallback to invoke when the year is selected.This doesn't imply a change on the selected date.
monthSelectedTCallback to invoke when the month is selected.This doesn't imply a change on the selected date.
dateClickedTCallback when the selected data changes.
selectedChangedTCallback when the currently selected data changes.
userSelectionnullCallback when any date is selected.

Properties for input[owlDateTime]

NameTypeRequiredDefaultDescription
owlDateTimeOwlDateTimeComponent<T>RequirenullThe date time picker that this input is associated with.
owlDateTimeFilter( date: T)=>boolean OptionalnullA function to filter date time.
disabledbooleanOptionalfalseWhen specify to true, it would disable the picker's input.
min<T>OptionalnullThe minimum valid date time.
max<T>OptionalnullThe maximum valid date time.
selectModesingle, range, rangeFrom, rangeToOptionalsingleSpecify the picker's select mode. single: a single value allowed, range: allow users to select a range of date-time, rangeFrom: the input would only show the 'from' value and the picker could only selects 'from' value, rangeTo: the input would only show the 'to' value and the picker could only selects 'to' value.
rangeSeparatorstringOptional-The character to separate the 'from' and 'to' in input value in range selectMode.

Events for input[owlDateTime]

EventsParameterDescription
dateTimeChangesource: OwlDateTimeInput, value: input value, input: the input elementCallback to invoke when change event is fired on this <input [owlDateTime]>
dateTimeInputsource: OwlDateTimeInput, value: input value, input: the input elementCallback to invoke when an input event is fired on this <input [owlDateTime]>.

Properties for [owlDateTimeTrigger]

NameTypeRequiredDefaultDescription
owlDateTimeTriggerOwlDateTimeComponent<T>RequirenullThe date time picker that this trigger is associated with.
disabledbooleanOptionalfalseWhen specify to true, it would disable the trigger.

Properties for [owlDateTimeTrigger]

NameTypeRequiredDefaultDescription
owlDateTimeTriggerOwlDateTimeComponent<T>RequirenullThe date time picker that this trigger is associated with.
disabledbooleanOptionalfalseWhen specify to true, it would disable the trigger.

Properties for owl-date-time-inline

NameTypeRequiredDefaultDescription
pickerTypeboth, calendar, timerOptionalbothSet the type of the dateTime picker. both: show both calendar and timer, calendar: only show calendar, timer: only show timer.
startViewmonth, year, multi-yearOptionalmonthThe view that the calendar should start in.
startAtT/nullOptionalnullThe moment to open the picker to initially.
endAtT/nullOptionalnullThe the default selected time for range calendar end time
firstDayOfWeeknumberOptional0Set the first day of week. Valid value is from 0 to 6. 0: Sunday - 6: Saturday
showSecondsTimerbooleanOptionalfalseWhen specify it to true, it would show a timer to configure the second's value
hideOtherMonthsbooleanOptionalfalseWhether to hide dates in other months at the start or end of the current month
hour12TimerbooleanOptionalfalseWhen specify it to true, the timer would be in hour12 format mode
stepHournumberOptional1Hours to change per step.
stepMinutenumberOptional1Minutes to change per step.
stepSecondnumberOptional1Seconds to change per step.
disabledbooleanOptionalfalseWhen specify to true, it would disable the picker.
owlDateTimeFilter( date: T)=>boolean OptionalnullA function to filter date time.
min<T>OptionalnullThe minimum valid date time.
max<T>OptionalnullThe maximum valid date time.
selectModesingle, range, rangeFrom, rangeToOptionalsingleSpecify the picker's select mode. single: a single value allowed, range: allow users to select a range of date-time, rangeFrom: the input would only show the 'from' value and the picker could only selects 'from' value, rangeTo: the input would only show the 'to' value and the picker could only selects 'to' value.

Localization and DateTime Format

Localization for different languages and formats is defined by OWL_DATE_TIME_LOCALE and OWL_DATE_TIME_FORMATS. You could learn more about this from here.

Dependencies

  • @angular/cdk (peer dependency) — provides the overlay the picker is rendered in. Remember to include the CDK overlay styles (@use '@angular/cdk/overlay-prebuilt.css';) unless you already use Angular Material. See How to Use.

Demo

  • Online doc is here
  • Online demos (StackBlitz) are here and here

License

  • License: MIT

Author

Maintained and updated by Daniel Moncada, original implementatiom by Daniel Pan

版本与发布记录

@danielmoncada/angular-datetime-picker 共发布 50 个版本,首次发布于 2020/02/12;过去 12 个月发布了 3 个版本。

版本发布日期距今
22.0.0latest2026/08/053 个月前
21.0.02026/01/289 个月前
20.0.12025/11/2011 个月前
20.0.02025/07/141.3 年前
19.1.22025/05/231.5 年前
19.1.12025/03/311.6 年前

其他发布通道:alhpa → 10.0.0-alpha.0。

关于 @danielmoncada/angular-datetime-picker 的常见问题

@danielmoncada/angular-datetime-picker 是什么?

Angular Date Time Picker

如何安装 @danielmoncada/angular-datetime-picker?

在项目目录运行 npm install @danielmoncada/angular-datetime-picker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^21.0.0 || ^22.0.0)、@angular/core(^21.0.0 || ^22.0.0)、@angular/cdk(^21.0.0 || ^22.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@danielmoncada/angular-datetime-picker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@danielmoncada/angular-datetime-picker 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@danielmoncada/angular-datetime-picker 可以商用吗?

@danielmoncada/angular-datetime-picker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@danielmoncada/angular-datetime-picker 的下载量有多少?

根据 npm 官方下载统计,@danielmoncada/angular-datetime-picker 在 2026/10/12 – 2026/11/10 这 30 天内被下载 226,158 次,日均约 7,539 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@danielmoncada/angular-datetime-picker 还在维护吗?

最新版本 22.0.0 发布于 2026/08/05(3 个月前);至今共发布 50 个版本,其中过去 12 个月发布了 3 个;首次发布于 2020/02/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。