Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker 12 hour am/pm format? #1578

Closed
acomito opened this issue Jul 19, 2017 · 9 comments
Closed

DatePicker 12 hour am/pm format? #1578

acomito opened this issue Jul 19, 2017 · 9 comments
Assignees
Labels

Comments

@acomito
Copy link

acomito commented Jul 19, 2017

What problem does this feature solve?

Common to use 12 hour am/pm format in the US, rather than military time.

What does the proposed API look like?

Either allow to pass in hh to the format, or have a prop (like antd web) 12hour={true}

warmhug added a commit to react-component/m-date-picker that referenced this issue Jul 24, 2017
warmhug added a commit to react-component/m-date-picker that referenced this issue Jul 31, 2017
* remove moment.js

* up HISTORY.md

* use constant var

* upgrade rmc-picker

* add test, remove unused code

* fix setMonth

* add use12Hours support

* fix use12Hours, ref ant-design/ant-design-mobile#1578

* improve HISTORY
@SpringsTea
Copy link

SpringsTea commented Feb 23, 2018

Doesn't appear to be working for me.

<DatePicker  
   showTime  
   use12Hours = {true} 
   allowClear={false}  
   format="YYYY-MM-DD HH:mm"  
   defaultValue={ moment(value) }   
   onChange={handleChange}/>

Still showing 24 hour time

@yingdongzhang
Copy link

@SpringsTea are you using React Native? It only works on web. https://mobile.ant.design/components/date-picker/

@SpringsTea
Copy link

Ah I see. For anyone else who gets stuck here, after digging through some doc I found something that mentioned that setting showTime to an object will be passed to the TimePicker, so you can make it work like this:

<DatePicker  
   showTime = {{ user12hours: true }} 
   allowClear={false}  
   format="YYYY-MM-DD HH:mm"  
   defaultValue={ moment(value) }   
   onChange={handleChange}/>

lixiaoyang1992 pushed a commit to lixiaoyang1992/ant-design-mobile that referenced this issue Apr 26, 2018
@developdeez
Copy link

developdeez commented Oct 14, 2018

I was able to get the 12 hour working using this but I can't get rid of the seconds...

 <DatePicker
                  showTime={{ use12Hours: true }}
                  format="YYYY-MM-DD HH:mm a"
                />

Anyone have a solution?

@flaviotsf
Copy link

@developdeez - this worked to format the time without seconds. Basically pass the format option to showTime as well:

  <DatePicker
              onChange={this.handleTimeChange}
              showTime={{ use12Hours: true, format: "HH:mm a" }}
              format="YYYY-MM-DD HH:mm a"
              value={this.props.socialEvent.eventDate}
            />

@chefThomas
Copy link

chefThomas commented Aug 7, 2019

An alternative is to interface directly with moment object spit out by datepicker. Use the format method.
Docs here.

moment.format('HH:mm a') for 12 hour format

Senior-Hayato-Suzuki pushed a commit to Senior-Hayato-Suzuki/react-date-picker that referenced this issue Feb 16, 2020
* remove moment.js

* up HISTORY.md

* use constant var

* upgrade rmc-picker

* add test, remove unused code

* fix setMonth

* add use12Hours support

* fix use12Hours, ref ant-design/ant-design-mobile#1578

* improve HISTORY
Senior-Hayato-Suzuki pushed a commit to Senior-Hayato-Suzuki/react-date-picker that referenced this issue Feb 26, 2020
* remove moment.js

* up HISTORY.md

* use constant var

* upgrade rmc-picker

* add test, remove unused code

* fix setMonth

* add use12Hours support

* fix use12Hours, ref ant-design/ant-design-mobile#1578

* improve HISTORY
@sahilpaudel
Copy link

 <DatePicker
            className={styles.edit_start_time}
            format="DD-MM-YYYY HH:mm A"
            showTime={{ use12Hours: true, format: "HH:mm A" }}
            onChange={onChange} onOk={onOk} />

This one works but if I select time for PM it goes beyond 12h as 20-03-2021 15:58 PM but I want it to be 20-03-2021 03:58 PM

@shubhankar30
Copy link

 <DatePicker
            className={styles.edit_start_time}
            format="DD-MM-YYYY HH:mm A"
            showTime={{ use12Hours: true, format: "HH:mm A" }}
            onChange={onChange} onOk={onOk} />

This one works but if I select time for PM it goes beyond 12h as 20-03-2021 15:58 PM but I want it to be 20-03-2021 03:58 PM

Use hh instead of HH

bigpeaches added a commit to bigpeaches/m-date-picker that referenced this issue Dec 23, 2022
* remove moment.js

* up HISTORY.md

* use constant var

* upgrade rmc-picker

* add test, remove unused code

* fix setMonth

* add use12Hours support

* fix use12Hours, ref ant-design/ant-design-mobile#1578

* improve HISTORY
@abdukadirov
Copy link

Doesn't appear to be working for me.

<DatePicker  
   showTime  
   use12Hours = {true} 
   allowClear={false}  
   format="YYYY-MM-DD HH:mm"  
   defaultValue={ moment(value) }   
   onChange={handleChange}/>

Still showing 24 hour time

Hi, my friend, you don't need to use use12Hours in order to get 12 hours, you should just change the format format="YYYY-MM-DD HH:mm" to format="YYYY-MM-DD hh:mm" , HH gives 24hours hh provides 12hours, I hope, I'm able to give you a solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests