lanjingling0510 / react-mobile-datepicker

🙊 👻 look a demo, Please imitate mobile environment.
https://codepen.io/lanjingling0510/pen/LRpOYp?editors=1010
MIT License
301 stars 145 forks source link

[Feature] 12 Hour AM/PM Support? #44

Open eastcoastcoder opened 5 years ago

eastcoastcoder commented 5 years ago

This library is awesome except for one flaw. There doesn't seem to be a way to set 12 hour time. rmc-date-picker supports this but has a lack of themes and the time doesn't seem to roll over continuously like this library. I was wondering if there is already support for this I'm just overlooking?

lanjingling0510 commented 4 years ago

@ethanx94 you can customize the format of the hour display content.

such as

const formatAMPM = (date) => {
    let hours = date.getHours();
    let ampm = hours >= 12 ? 'pm' : 'am';;
    hours = hours % 12;
    hours = hours ? hours : 12; // the hour '0' should be '12'
    return hours + ampm;
}

// ....

render() {
    return (
        <DatePicker
        dateConfig={{
            'hour': {
                format: value => this.formatAMPM(value),
                caption: 'æ—¶',
                step: 1,
            },
        }} />
    );
}
embargiel commented 3 years ago

@lanjingling0510 Nice example, but the question is if it is possible to have AM/PM as a third element with possibility to scroll in the same way as minutes or hours