nsdate

Hardware-dependent NSDateFormatter dateFromString: bug (returns nil)

这一生的挚爱 提交于 2019-11-27 05:29:13
I have several date strings that I need to convert to NSDates. My parsing code is the following: NSString *s = [pair objectForKey:@"nodeContent"]; NSDateFormatter *f = [[NSDateFormatter alloc] init]; [f setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZ"]; self.date = [f dateFromString:s]; The above code works fine in all the devices and simulators we've tested. The strange thing is that when the above code runs on any iPhone 5 running iOS 6.1 or 7.0.x , the line self.date = [f dateFromString:s]; returns nil every time. I have checked and the string s exists and contains the same characters when compared

How do I get weekday and/or name of month from a NSDate variable?

一曲冷凌霜 提交于 2019-11-27 05:28:01
问题 Alright. The problem we're having is that we have NSStrings filled with dates in the format of yyyyMMdd and what we want to do is to get the current weekday and name of month. The function dagOmvandlare converts the datestring to weekday and month. The function is then called on viewDidload to name all our button-titles from english to swedish months. our current solution is looking like this: -(NSString *)dagOmvandlare:(id) suprDatum{ NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc

How to get NSDate day, month and year in integer format?

主宰稳场 提交于 2019-11-27 05:09:29
问题 I want to get the day, month and year components of NSDate in integer form i.e. if the date is 1/2/1988 then I should get 1, 2 and 1988 separately as an integer. How can I do this in iOS? I found the similar question but the method descriptionWithCalendarFormat : gives a warning and seems to be deprecated by now. 回答1: Here you are, NSDate *currentDate = [NSDate date]; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:NSCalendarUnitYear

iOS NSDate() returns incorrect time

China☆狼群 提交于 2019-11-27 04:49:53
问题 I am trying to get current date in Swift using NSDate() . When I create breakpoint and stop application, I can see that there is 3 hours difference with devices' system time. Application is running on real iPhone. How to fix this? I also wrote the following in App Delegate to be sure: NSTimeZone.setDefaultTimeZone(NSTimeZone(name: "Europe/Kiev")!) But it still does not work. 回答1: It doesn't return the wrong time. It returns exactly the right time. NSDate doesn't have any timezone information.

NSDateFormatter, am I doing something wrong or is this a bug?

女生的网名这么多〃 提交于 2019-11-27 04:21:37
I'm trying to print out the date in a certain format: NSDate *today = [[NSDate alloc] init]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *dateStr = [dateFormatter stringFromDate:today]; If the iPhone is set to 24 hour time, this works fine, if on the other hand the user has set it to 24 hour time, then back to AM/PM (it works fine until you toggle this setting) then it appends the AM/PM on the end even though I didn't ask for it: 20080927030337 PM Am I doing something wrong or is this a bug with firmware 2.1? Edit 1

How can i get next date using NSDate? [duplicate]

旧巷老猫 提交于 2019-11-27 04:20:53
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: iOS and finding Tomorrow How can i get next date using NSDate. Please send me the solution. 回答1: In the following, yourDate represents your input NSDate; nextDate represents the next day. // start by retrieving day, weekday, month and year components for yourDate NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *todayComponents = [gregorian components:

How to convert string to date to string in Swift iOS? [duplicate]

与世无争的帅哥 提交于 2019-11-27 04:18:24
问题 This question already has answers here : Converting NSString to NSDate (and back again) (17 answers) Closed 4 years ago . Am learning swift and am struck in converting the date String to NSDate to string. Am getting the date string in this format "Thu, 22 Oct 2015 07:45:17 +0000". I need to show the date in the MM-dd-yyyy format. I tried the following code but, it returns "null". let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM-dd-yyyy" dateFormatter.dateStyle =

Sort NSArray of custom objects by their NSDate properties

你说的曾经没有我的故事 提交于 2019-11-27 04:15:53
I am attempting to sort an NSArray that is populated with custom objects. Each object has a property startDateTime that is of type NSDate. The following code results in an array, sortedEventArray , populated but not sorted. Am I going about this the completely wrong way or am I just missing something small? NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"startDateTime" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor]; NSArray *sortedEventArray = [nodeEventArray sortedArrayUsingDescriptors:sortDescriptors]; Are you sure that the

How to calculate the age based on NSDate

折月煮酒 提交于 2019-11-27 04:12:05
问题 how to calculate the age based on the birth date in this format 6/24/1976 mon/date/year... 回答1: Many of these answers don't properly account for leap years and such, best is to use Apple's methods instead of dividing by constants. Swift let birthday: NSDate = ... let now = Date() let ageComponents = calendar.dateComponents([.year], from: birthday, to: now) let age = ageComponents.year Objective-C NSDate* birthday = ...; NSDate* now = [NSDate date]; NSDateComponents* ageComponents = [

How to get time (hour, minute, second) in Swift 3 using NSDate?

﹥>﹥吖頭↗ 提交于 2019-11-27 03:48:15
How can you determine the hour, minute and second from NSDate class in Swift 3? In Swift 2: let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.Hour, fromDate: date) let hour = components.hour Swift 3? In Swift 3.0 Apple removed 'NS' prefix and made everything simple. Below is the way to get hour, minute and second from 'Date' class (NSDate alternate) let date = Date() let calendar = Calendar.current let hour = calendar.component(.hour, from: date) let minutes = calendar.component(.minute, from: date) let seconds = calendar.component(.second,