入门
复制一个包含安装步骤和本插件的完整Markdown指南的设置命令。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-date-picker`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/date-picker/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
准备好粘贴您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中。
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-date-picker` plugin in my project.如果您更喜欢手动设置,请运行以下命令并按照以下平台特定的说明进行安装:
npm install @capgo/capacitor-date-pickernpx cap sync导入
导入import { DatePicker } from '@capgo/capacitor-date-picker';选择日期
选择日期const result = await DatePicker.present({ mode: 'date', date: '2026-05-27', min: '2026-01-01', max: '2026-12-31', format: 'yyyy-MM-dd', title: 'Select date',});
console.log(result.value);选择时间
时间选择const result = await DatePicker.present({ mode: 'time', is24h: true, minuteStep: 15, format: 'HH:mm', title: 'Select time',});
console.log(result.value);选择日期和时间
日期选择const result = await DatePicker.present({ mode: 'dateAndTime', date: '2026-05-27T14:30:00', format: "yyyy-MM-dd'T'HH:mm:ss", title: 'Select date and time',});选择月份
选择时间段const result = await DatePicker.present({ mode: 'yearAndMonth', date: '2026-05-01', format: 'yyyy-MM', title: 'Select month',});时间段选择
Pick A Timeconst range = await DatePicker.presentRange({ start: '2026-05-01', end: '2026-05-27', format: 'yyyy-MM-dd', startTitle: 'Start date', endTitle: 'End date',});
console.log(range.start, range.end, range.value);隐藏时间选择器
时间选择器隐藏await DatePicker.hide();平台选项
平台选项await DatePicker.present({ mode: 'date', date: '2026-05-27', title: 'Select date', ios: { style: 'inline', theme: 'light', }, android: { theme: 'light', },});常用选项
常用选项| 选项 | 描述 |
|---|---|
mode | date, time, dateAndTime, yearAndMonth, countDownTimer或 range. |
date | 初始选中的值。 |
min / max | 最小和最大可选择值。 |
format | 输出格式。支持 ISO、Java/Unicode 和常见 Moment 风格格式。 |
title | 对话框标题。 |
locale | 本地选择器使用的区域设置(支持的区域设置中)。 |
timezone | 用于解析和格式化的时区。 |
is24h | 优先使用 24 小时时间。 |
minuteStep | 时间选择器分钟间隔。 |
doneText / cancelText | 自定义操作标签。 |
示例应用
名为“示例应用”的部分本仓库包含一个示例应用程序,Capacitor,它可以打开本地日期选择器、时间选择器和范围选择器。 hide(),和插件版本调用。
| iOS | Android |
|---|---|
![]() | ![]() |
@API参考
API参考完整的@API参考在包README和TypeScript定义中维护:

