diff --git a/components/date-picker/demo/time.md b/components/date-picker/demo/time.md
index 91a857cb03..1e02d1db6e 100644
--- a/components/date-picker/demo/time.md
+++ b/components/date-picker/demo/time.md
@@ -37,8 +37,8 @@ ReactDOM.render(
/>
= 0,
- showMinute: timeFormat.indexOf('mm') >= 0,
- showHour: timeFormat.indexOf('HH') >= 0,
use12Hours: (props.showTime && props.showTime.use12Hours),
};
const columns = getColumns(rcTimePickerProps);
diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx
index 84e3329ae7..35b999059a 100644
--- a/components/time-picker/index.tsx
+++ b/components/time-picker/index.tsx
@@ -6,6 +6,19 @@ import assign from 'object-assign';
import injectLocale from '../locale-provider/injectLocale';
import defaultLocale from './locale/zh_CN';
+export function generateShowHourMinuteSecond(format: string) {
+ // Ref: http://momentjs.com/docs/#/parsing/string-format/
+ return {
+ showHour: (
+ format.indexOf('H') > -1 ||
+ format.indexOf('h') > -1 ||
+ format.indexOf('k') > -1
+ ),
+ showMinute: format.indexOf('m') > -1,
+ showSecond: format.indexOf('s') > -1,
+ };
+}
+
export interface TimePickerProps {
className?: string;
size?: 'large' | 'default' | 'small';
@@ -120,9 +133,7 @@ abstract class TimePicker extends React.Component {
return (
-1 || format.indexOf('h') > -1}
- showMinute={format.indexOf('mm') > -1}
- showSecond={format.indexOf('ss') > -1}
+ {...generateShowHourMinuteSecond(format)}
{...props}
ref={this.saveTimePicker}
format={format}