@capawesome-team/capacitor-datetime-picker

中文文档
8.2.0发布于 2026/10/01MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.8万

Capacitor plugin that lets the user easily enter both a date and a time on Android and iOS.

原始使用文档
文档目录25 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Installation
  5. Configuration
  6. Demo
  7. Usage
  8. Present a date, time, or datetime picker
  9. Let the user pick a month and year only
  10. API
  11. present(...)
  12. cancel()
  13. Interfaces
  14. FAQ
  15. What happens when the user cancels the picker?
  16. How can I close the picker programmatically?
  17. How do I restrict which dates the user can select?
  18. How do I let the user pick only a month and year?
  19. Can I change the language and theme of the picker?
  20. Does this plugin work on the Web?
  21. Related Plugins
  22. Credits
  23. Newsletter
  24. Changelog
  25. License

Capacitor Datetime Picker Plugin

Capacitor plugin for seamless date and time selection with advanced features like localization, theming, and more. Available for Android and iOS.

Features

The Capacitor Datetime Picker plugin is one of the most feature-rich date and time selection solutions for Capacitor apps. Here are some of the key features:

  • 🖥️ Cross-platform: Supports Android and iOS.
  • 📅 Multiple modes: Date, time, datetime, and month picker modes.
  • 🌍 Localization: Support for BCP 47 language tags.
  • 🎨 Theming: Auto, light, and dark theme support.
  • ⚡ Custom formats: Define your own date/time format strings.
  • 🔒 Min/Max constraints: Set minimum and maximum selectable dates/times.
  • 📱 Native UI: Uses platform-specific picker components.
  • ⚙️ Flexible configuration: Customizable button texts and picker modes.
  • 🤝 Compatibility: Works alongside the Action Sheet, Dialog and Localization plugins.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Datetime Picker plugin is typically used whenever an app needs the user to enter a date or time, for example:

  • Appointment booking: Let users pick a date and time for a reservation and restrict the selection with minimum and maximum constraints.
  • Profile forms: Ask for a date of birth with a native, localized date picker.
  • Reminders and alarms: Let users choose a time of day using the native time picker, optionally with a custom minute interval on iOS.
  • Reports and statements: Let users select a month and year only, for example to filter a monthly report, using the month mode.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated
5.x.x5.x.xDeprecated

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome-team/capacitor-datetime-picker` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands:

npm install @capawesome-team/capacitor-datetime-picker
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

AndroidiOS
Android DemoiOS Demo

Usage

The following examples show how to present a date, time, or datetime picker, and how to let the user pick a month and year only.

Present a date, time, or datetime picker

Open the native picker with the present(...) method. Use the mode option to choose between a date, time, or datetime picker, and customize the theme, locale, and button texts as needed. Only available on Android and iOS:

import { DatetimePicker } from '@capawesome-team/capacitor-datetime-picker';

const present = async () => {
  const date = new Date('1995-12-24T02:23:00');

  const { value } = await DatetimePicker.present({
    cancelButtonText: 'Cancel',
    doneButtonText: 'Ok',
    mode: 'time',
    value: date.toISOString(),
    theme: 'dark',
    locale: 'en-US',
  });

  return value;
};

Let the user pick a month and year only

Use the month mode to let the user pick a month and year without a day or time, for example to filter a monthly report. The returned value is the first day of the selected month:

import { DatetimePicker } from '@capawesome-team/capacitor-datetime-picker';

const presentMonth = async () => {
  const { value } = await DatetimePicker.present({
    cancelButtonText: 'Cancel',
    doneButtonText: 'Ok',
    mode: 'month',
    value: '2026-05',
    format: 'yyyy-MM',
    locale: 'en-US',
  });

  return value;
};

API

present(...)

present(options?: PresentOptions | undefined) => Promise<PresentResult>

Open the datetime picker.

An error is thrown if the input is canceled or dismissed by the user.

On Android, the picker is dismissed (the promise rejects with the dismissed error code) if the system language, font size or layout direction changes while it is open.

Only available on Android and iOS.

ParamType
optionsPresentOptions

Returns: Promise<PresentResult>

Since: 0.0.1


cancel()

cancel() => Promise<void>

Cancel the currently active datetime picker.

If there is no active picker, this method does nothing.

Only available on Android and iOS.

Since: 7.2.0


Interfaces

PresentResult

PropTypeDescriptionSince
valuestringThe value entered by the user. The format of this value matches the value of the format parameter.0.0.1

PresentOptions

PropTypeDescriptionDefaultSince
cancelButtonTextstringThe cancel button text.'Cancel'0.0.1
doneButtonTextstringThe done button text.'Ok'0.0.1
formatstringThe format in which values are received and returned.'yyyy-MM-dd'T'HH:mm:ss.sss'Z''0.0.1
localestringBCP 47 language tag to define the language of the UI.0.0.2
maxstringThe latest date and time to accept. The format of this value must match the value of the format parameter. This value must specify a date string later than or equal to the one specified by the min attribute.0.0.1
minstringThe earliest date and time to accept. The format of this value must match the value of the format parameter. This value must specify a date string earlier than or equal to the one specified by the max attribute.0.0.1
mode'date' | 'time' | 'datetime' | 'month'Whether you want a date, time, datetime or month picker. The month mode (since 8.1.0) lets the user pick a month and year only. Unlike the other modes, it uses a custom (non-native) UI on both platforms, because neither Android nor iOS provide a native month-only picker. The returned value is the first day of the selected month at 00:00:00 local time.'datetime'0.0.1
theme'auto' | 'light' | 'dark'Choose the theme that the datetime picker should have. With auto the system theme is used. This value overwrites the theme configuration value. On iOS 26 and later, the picker uses the system's Liquid Glass sheet, so the theme only selects its light or dark appearance. Only available on Android and iOS. Spinner options only available on Android0.0.1
valuestringThe predefined value when opening the picker. The format of this value must match the value of the format parameter.0.0.1
androidTimePickerMode'clock' | 'spinner'Whether to use the spinner or clock mode for the time picker on Android. This value overwrites the androidTimePickerMode configuration value. Only available on Android.5.1.0
androidDatePickerMode'spinner' | 'calendar'Whether to use the calendar or spinner mode for the date picker on Android. This value overwrites the androidDatePickerMode configuration value. Only available on Android.5.1.0
minuteIntervalnumberThe minute interval of the time picker. This controls the granularity of the minute selector (e.g., 15 for 0, 15, 30, 45). The value must be evenly divisible into 60. Only available on iOS when using time or datetime modes. On Android, this parameter is ignored.17.1.0

FAQ

What happens when the user cancels the picker?

The present(...) method throws an error if the input is canceled or dismissed by the user. Make sure to catch this error in your code, for example to keep the previous value.

How can I close the picker programmatically?

Use the cancel() method to cancel the currently active datetime picker, for example when your app is sent to the background. If there is no active picker, this method does nothing.

How do I restrict which dates the user can select?

Use the min and max options of the present(...) method to define the earliest and latest date and time to accept. The format of both values must match the value of the format parameter.

How do I let the user pick only a month and year?

Set the mode option to month. Unlike the other modes, the month picker uses a custom (non-native) UI on both platforms, because neither Android nor iOS provide a native month-only picker. The returned value is the first day of the selected month at 00:00:00 local time. See the usage example above.

Can I change the language and theme of the picker?

Yes, use the locale option with a BCP 47 language tag to define the language of the UI, and the theme option to choose between auto, light, and dark. With auto, the system theme is used.

Does this plugin work on the Web?

No, this plugin is only available on Android and iOS, where it uses platform-specific picker components. The present(...) and cancel() methods are not available on the Web.

  • Action Sheet: Show native action sheets.
  • Dialog: Display native alert, confirm, and prompt dialogs.
  • Localization: Read the user's preferred locales to localize the picker.
  • Option Picker: Let the user pick an option from a list with a native picker.

Credits

The iOS implementation of this plugin is based on RPicker which is licensed under MIT.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capawesome-team/capacitor-datetime-picker 共发布 19 个版本,首次发布于 2023/03/19;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.0latest2026/10/011 个月前
8.1.52026/09/052 个月前
8.1.42026/09/052 个月前
8.1.32026/09/022 个月前
8.1.22026/08/162 个月前
8.1.12026/06/154 个月前

其他发布通道:dev → 5.0.0-dev.da70913.1692263211。

关于 @capawesome-team/capacitor-datetime-picker 的常见问题

@capawesome-team/capacitor-datetime-picker 是什么?

Capacitor plugin that lets the user easily enter both a date and a time on Android and iOS.

如何安装 @capawesome-team/capacitor-datetime-picker?

在项目目录运行 npm install @capawesome-team/capacitor-datetime-picker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capawesome-team/capacitor-datetime-picker 支持 TypeScript 吗?

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

@capawesome-team/capacitor-datetime-picker 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capawesome-team/capacitor-datetime-picker 可以商用吗?

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

@capawesome-team/capacitor-datetime-picker 的下载量有多少?

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

@capawesome-team/capacitor-datetime-picker 还在维护吗?

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