12-hour format for Xcode-settings in a "Timepicker" nsdate

Source: Internet
Author: User

I am using the NSDate object and made up my iphone with a 24-hour format, so when I'm testing my app, everything works, but a friend of mine tries the app on his iphone Codego.net, but the 12-hour format, after study, I found the issue was dated, and I don't know why this set date selector and a selector, so I read the values from the database (yes, I've checked the values, they're correct, it's not a value issue), So all the data is formatted and put together as a nsdate, and then I set the date selector and selector with the date I just created

NSDateFormatter *currentDate = [[[NSDateFormatter alloc] init] autorelease];[currentDate setDateFormat:@"yyyy-MM-dd HH:mm"];NSDate * startDate =[currentDate dateFromString:[NSString stringWithFormat:@"%d-%d-%d %d:%d",yearVal,monthVal,dayVal,hourVal,minVal]];[datePicker setDate:startDate];[timePicker setDate:startDate];

So, yearval,monthval,dayval,hourval,minval are all nsintegers ... The problem is that it works perfectly if your iphone/ipod's 24-hour clock is set, but if you have 12-hour format, it crashes and shows that

> *** Assertion failure in -[UIDatePickerView _updateBitsForDate:forced:andReload:animateIfNeeded:], /SourceCache/UIKit/UIKit-1914.85/UIDatePicker.m:1200 2012-06-29> 01:19:15.753 MyApp[1215:707] *** Terminating app due to uncaught> exception ‘NSInternalInconsistencyException‘, reason: ‘Invalid> parameter not satisfying: date‘> *** First throw call stack: (0x3710188f 0x34e06259 0x37101789 0x379403a3 0x31042807 0x30f616c5 0x30f61563 0x31042385 0xf48ef 0xf7bd3> 0x30e0ec8b 0x30e1b1e9 0x30e1b059 0x30e1af3f 0x30e1a7c1 0x30e1a503> 0x30e0eaff 0x30e0e7d5 0xdd945 0x30e8793d 0x30f01627 0x37972933> 0x370d5a33 0x370d5699 0x370d426f 0x370574a5 0x3705736d 0x33816439> 0x30e03cd5 0xd4cbb 0xd4c60) terminate called throwing an> exception(gdb)

So please, if you have any ideas on how to solve this problem, I appreciate your help oh, I have read, HH returns time in 24-hour format, OK, I have all the hh, so I don't understand why I've been watching "I" or "PM" in Nslogs i's print debugging first thank you oh, sorry, I almost forgot, if I could.

[datePicker setDate:startDate];[timePicker setDate:startDate];

The app does not crash, but of course, it does not show and the date I need to note: I need 24 hours format, if I decide to choose the morning with the PM format, I will have to change all my apps and make up, I don't have enough
This address: codego.net/474673/
--------------------------------------------------------------------------------------------------------------- ----------
1. Take a look at this like: think the second answer may be the best for you. Then, depending on whether the clock is 12-hour or 24-hour, you can set [the currentdate Setdateformat: ...] accordingly. If you want a 12-hour clock, then set the currentdate as follows:

[currentDate setDateFormat:@"yyyy-MM-dd h:mm:ss a"];

If you want to have a 24-hour system, then set the currentdate as follows:

[currentDate setDateFormat:@"yyyy-MM-dd HH:mm"];


This article title: 12-hour format for Xcode-in a "timepicker" setting of the NSDate
This address: codego.net/474673/

12-hour format for Xcode-settings in a "Timepicker" nsdate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.