跳过内容

开始使用

GitHub

安装

安装

您可以使用我们的 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-picker
npx 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',
});
const 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',
},
});
选项描述
modedate, time, dateAndTime, yearAndMonth, countDownTimerrange.
date初始选中值。
min / max最小和最大可选择值。
format输出格式。支持 ISO、Java/Unicode 和常见 Moment-style 格式。
title对话标题。
locale本地选择器使用的区域设置(支持本地选择器)。
timezone用于解析和格式化的时区。
is24h偏好 24 小时时间。
minuteStep时间选择器分钟间隔。
doneText / cancelText自定义操作标签。

仓库包含一个 Capacitor 示例应用,用于打开原生日期选择器、时间选择器、范围选择器和插件版本调用。 hide()iOS

Android动画 iOS demo:@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-date-picker 打开、选择日期并关闭
动画 Android demo:@capgo/capacitor-date-picker 打开、选择日期并关闭Animated Android demo of @capgo/capacitor-date-picker opening, selecting a date, and closing

The complete API reference is maintained in the package README and TypeScript definitions: