nsdate

NSDate et al woes on iOS 4.2

拈花ヽ惹草 提交于 2019-12-08 00:07:05
问题 I believe that NSDate/NSCalendar has a bug or two on iOS 4.2. [[NSDate date] description] always prints using GMT, i.e. the local time zone setting is ignored. Has been reported previously, but is included to hopefully better explain the output below. [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSEraCalendarUnit forDate:dateA] Doesn't always return the correct value, while this does: [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:dateA] Based on a

Remove milliSeconds from String in iOS

我怕爱的太早我们不能终老 提交于 2019-12-07 22:38:00
问题 Trying to remove milli seconds from String(date) NSString *dateString = @"2016-05-16 13:17:34.674194"; NSDateFormatter* formater = [[NSDateFormatter alloc] init]; [formater setDateFormat:@"dd/MM/yyyy HH:mm:ss"]; NSDate *date = [formater dateFromString:dateString]; NSLog(@"%@",[formater stringFromDate:date]); and i'm getting null i'm expecting o/p something like (with out milli seconds) "06/05/2016 13:17:34" Please suggest... 回答1: Copy and paste this Code working Perfectly NSString *dateString

stringFromDate always NIL

假如想象 提交于 2019-12-07 22:16:21
问题 I know this is a repetitive question, but after searching for many similar questions on stackoverflow and google, none of the solutions worked for me. I am tring to convert date which I receive from DB to string format to display in iPhone app. I am converting date to string in following manner, but [dateFormat stringFromDate:beginDate] always return nil. NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MMM dd hh:mm a"]; NSString *dateString =

finding NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)?

百般思念 提交于 2019-12-07 19:52:53
问题 Is there a quick way in Objective-C of identifying NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)? I can't quite see anyway other than manually walking through each NSDate in the array and then using NSDateComponents to break out the hour/minute/second...Not even sure if there is a simple way to get the time from an NSDate in a fashion that represents a fraction of 24hours, as this might help a little. (e.g. 6pm would be 18/24 = 0.75 in this case) 回答1: There is

iPhone UIDatePicker setMaximumDate

时光毁灭记忆、已成空白 提交于 2019-12-07 18:15:41
问题 I am trying to build a datepicker which has today as a minimum date and 1 Feb 2011 as Maximum date. I have set the minimum date as followed [picker setMinimumDate: [NSDate date]]; and this works just fine but the MaximumDate does not seem to be correct. [picker setMaximumDate: [NSDate dateWithNaturalLanguageString:@"11/02/01"]]; How do I set the maximum date correctly? 回答1: Found the answer. Thanks anyway for your help. [picker setDatePickerMode:UIDatePickerModeDate]; NSDateFormatter*

Convert an array of times from 24hr to 12 hr in Swift

*爱你&永不变心* 提交于 2019-12-07 16:55:59
问题 I have an array like this: arrayTimes = ["16:00", "16:30", "17:00", "17:30", "18:00", "18:30"] and I want to convert the array from 24 hr to 12 hr.. This is what I have so far which converts the first number in the array.. I'm missing something but I can't work it out. func convertTimes(){ for twelve in arrayTimes{ var two = arrayTimes[0] let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "H:mm" let date12 = dateFormatter.dateFromString(two)! dateFormatter.dateFormat = "h:mm a"

NSDateFormatter can't parse '1988-04-10' to NSDate instance in iOS 6 . Is it a bug?

不羁岁月 提交于 2019-12-07 16:18:23
问题 I encountered a stranger question. NSDateFormatter can't parse 1988-04-10 to NSDate instance in iOS 6. But it works in iOS 4 and iOS 5. Is it a bug? Following is the code. It is very simple. NSArray *values = @[@"1988-04-09", @"1988-04-10", @"1988-04-11"]; NSDateFormatter* df = [[NSDateFormatter alloc] init]; NSLocale *posixLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [df setLocale:posixLocale]; [df setDateFormat:@"yyyy'-'MM'-'dd"]; NSLog(@"timeZone:%@, locale:%@", df

converting an float to NSDate

北城余情 提交于 2019-12-07 15:22:12
问题 I want to convert a float to a NSDate I converted a NSDate into a float using this: // Turn the date into Integers NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendarUnit unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:nsdate_wakeTime]; NSInteger hour = [dateComponents hour]; NSInteger min = [dateComponents minute]; //Convert the time in 24

Calculating first and last days of current week

爱⌒轻易说出口 提交于 2019-12-07 15:11:33
问题 Reference to pre-answered question at: Getting first and last days of current week There are two answers in the above link. One of them is theoretical and the other is in a language called as PyObjC (Python-Objective C bridge language), and a quick google search confirms that PyObjC does not work with iPhone SDK. So regarding the question, how is it possible to get the PyObjC code translated to be compatible with iPhone SDK. Target: Supposing today (Tue.) is 19th, and Sun. was 17th (start of

NSDictionary with NSDates as keys

情到浓时终转凉″ 提交于 2019-12-07 12:10:44
问题 Is it possible to have an NSdictionary where the keys are NSDates and also have it writeable/archiveable to disk? 回答1: Not using property lists, as only string keys are allowed there. You should be able to write it using NSKeyedArchiver , but that has the disadvantage of being a more opaque format. Alternatively, you could of course make a copy of the dictionary where you convert the dates to strings. 回答2: Yes, this should work just fine - and NSDate elements are also suitable for plist