Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Date picker - turn animation off for minutes
-
Hi, I'm using date picker and want to fix or freeze minutes at '00' but still want to be pick date, hour and AM/PM. I'm guessing that I need to use selectRow_inComponent_animated_() but am not sure how. Thanks!
-
@vkcatfish you could always hide the minutes area...
Something likeimport ui v = ui.DatePicker() v.frame = (0,0,400,200) v.background_color = 'lightgray' v.mode = ui.DATE_PICKER_MODE_DATE_AND_TIME hi = ui.View() x = 250 hi.frame = (x,0,v.width-x,v.height) hi.background_color = 'lightgray' v.add_subview(hi) v.present('sheet')
-
@vkcatfish if you mean UIDatePicker, see a solution at bottom of here
Tried this without success. I can't help you more.
NSDateFormatter = ObjCClass('NSDateFormatter') dateFormatter = NSDateFormatter.alloc().init() dateFormatter.setTimeZone_(ObjCClass('NSTimeZone').local) dateFormatter.setDateFormat_('yyyy-MM-dd HH:00') myStringDate = dateFormatter.stringFromDate_(objc.date) myDateDate = dateFormatter.dateFromString_(myStringDate) objc.setDate_animate_(myDateDate, True)
-
@vkcatfish This works on an iPad if your ok with just hiding the minutes. It would require some adjustments on an iPhone.
import ui from datetime import datetime def date_changed(sender): print(sender.date) print(sender.date.strftime("%Y-%m-%d %H:%M")) print(sender.date.strftime("%Y-%m-%d %I %p")) v = ui.DatePicker() v.name = 'Date Picker' v.frame = (0,0,400,200) v.background_color = 'lightgray' v.mode = ui.DATE_PICKER_MODE_DATE_AND_TIME v.action = date_changed #v.date = datetime.strptime('2022-11-30 14:11', "%Y-%m-%d %H:%M") dtm = datetime.now() v.date = datetime(dtm.year, dtm.month, dtm.day, dtm.hour) hi = ui.View() x = 250 hi.frame = (x, 0, 50, v.height) hi.background_color = 'lightgray' v.add_subview(hi) v.present('sheet')
-
Python f-strings can usually be used to shorten and accelerate
.strfdate()
and.strftime()
...>>> datetime.now().strftime("%Y-%m-%d %H:%M") '2022-12-01 08:04' >>> f"{datetime.now():%Y-%m-%d %H:%M}" '2022-12-01 08:04' >>> datetime.now().strftime("%Y-%m-%d %I %p") '2022-12-01 08 AM' >>> f"{datetime.now():%Y-%m-%d %I %p}" '2022-12-01 08 AM'