nsdate

Does [NSDate date] return the local date and time?

故事扮演 提交于 2019-11-27 15:15:53
Am I stupid? All this time I thought [NSDate date] returned the local date and time. After having some trouble with NSStringformatter/stringFromdate/dateFromString today I noticed that my [NSDate date] was returning 2011-03-06 11:00:00 +0000. After researching this I see that [NSDate date] returns a raw date which is always GMT. What purpose does the gmt offset portion serve if it always shows +0000? Also I do not understand [myDate description]. The docs says it is supposed to display gmt offset as well as dst information. I get the same thing as [NSDate date]. Bottom line for me, if I use

iOS Swift 3 : Convert “yyyy-MM-dd'T'HH:mm:ssZ” format string to date object

99封情书 提交于 2019-11-27 14:57:01
问题 Hello i have a dictionary self.publishedAt = dictionary["publishedAt"] as? NSString in which i'm getting date " 2017-01-27T18:36:36Z ". I want to convert it in readable format : dd-MM-yyyy hh:mm:ss . i tried via let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy hh:mm:ss" let date = dateFormatter.date(from: (self.publishedAt as? String)!) print("EXACT_DATE : \(date)") But getting nil. :( What is the correct way to get date in simple format? 回答1: You need an input

Data Formatters temporarily unavailable

馋奶兔 提交于 2019-11-27 14:51:40
Im trying to use Date Formatters (NSDateFormatter), but I keep getting this error: Program received signal: “EXC_BAD_ACCESS”. Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib") This is nothing to do with NSDateFormatter - the message pasted in saying "Data Formatters" is correct. You will get this message in several situations, possibly most commonly when unable to find a linked in shared library at launch time. You may also get it when short of memory while running, in which case

NSDate between two given NSDates

亡梦爱人 提交于 2019-11-27 14:49:50
I am interested in creating a method to find if the current date falls between certain times on any given day. It is for a scheduling program, so I want to find what event is occurring at the current time. Every day has the same set of times: 820-900, 900-940, 940-1020, etc. Since this must be done on any given day I do not know how to create an NSDate with a certain time. I think this might be done with NSTimeInterval but I am not sure how to instantiate that. This isn't perfect, but you could use [NSDate compare:] to check your date against both boundaries: NSDate *firstDate = ... NSDate

Why isn't my time zone being saved into my NSDate?

我怕爱的太早我们不能终老 提交于 2019-11-27 14:43:23
问题 I must initialize an NSDate object from NSString in objective-c. I do it like this: NSString *dateString = [[webSentence child:@"DateTime"].text stringByReplacingOccurrencesOfString:@"T" withString:@" "]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-mm-dd HH:mm:ss"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Budapest"]]; NSDate *date = [[NSDate alloc] init]; date = [dateFormatter dateFromString:dateString]; E.g:

NSDateFormatter and Time Zone issue?

感情迁移 提交于 2019-11-27 14:20:50
I have a string with time in GMT and i want to make it according to the system time zone but its not working properly - NSLog(@"Time Str = %@",Time); NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"dd-MM-yyyy hh:mm a"]; [NSTimeZone resetSystemTimeZone]; NSLog(@"system time zone = %@",[NSTimeZone systemTimeZone]); [dateFormat setTimeZone:[NSTimeZone systemTimeZone]]; NSDate *date = [dateFormat dateFromString:Time]; [dateFormat setTimeZone:[NSTimeZone systemTimeZone]]; NSLog(@"date from string = %@",date); NSLog(@"string from date = %@",[dateFormat

Why does NSDateFormatter return nil date for these 4 time zones?

夙愿已清 提交于 2019-11-27 14:19:30
问题 Try running this in iOS6 (haven't tested pre iOS6): NSDateFormatter *julianDayDateFormatter = nil; julianDayDateFormatter = [[NSDateFormatter alloc] init]; [julianDayDateFormatter setDateFormat:@"g"]; for (NSString *timeZone in [NSTimeZone knownTimeZoneNames]) { julianDayDateFormatter.timeZone = [NSTimeZone timeZoneWithName: timeZone]; NSDate *date = [julianDayDateFormatter dateFromString:[NSString stringWithFormat:@"%d", 2475213]]; if (date == nil) NSLog(@"timeZone = %@", timeZone); } and

How to set repeat frequency in User Notification [duplicate]

≯℡__Kan透↙ 提交于 2019-11-27 14:05:52
问题 This question already has answers here : How do I set an NSCalendarUnitMinute repeatInterval on iOS 10 UserNotifications? (3 answers) Closed 2 years ago . Till iOS 9 we write local notifications like this UILocalNotification* localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = pickerDate; localNotification.alertBody = self.textField.text; localNotification.timeZone = [NSTimeZone defaultTimeZone]; localNotification.repeatInterval = NSCalendarUnitMinute;

Convert a NSDate to milliseconds epoch time

感情迁移 提交于 2019-11-27 13:42:13
问题 I need to be able to convert a date to a time stamp, an epoch in milliseconds. All I see online are for converting milliseconds to NSDate and not the other way round. Any help out there? 回答1: NSTimeInterval is a double that already contains sub-second data after the decimal point. Depending what you need, your conversion could be a simple as multiplying by 1000. - (void)testDateFormat { NSDate *date = [NSDate date]; NSLog(@"Time: %f", floor([date timeIntervalSince1970] * 1000)); NSLog(@"Time:

Creating an NSDateFormatter in Swift? [closed]

喜你入骨 提交于 2019-11-27 13:33:21
I am new to swift and am very unfamiliar with Objective-C. Could someone help me convert this to Swift? I got this code from Ray Wenderlich's best iOS practices - http://www.raywenderlich.com/31166/25-ios-app-performance-tips-tricks Where would you put this code? Would it go in a class file full of global variables? - (NSDateFormatter *)formatter { static NSDateFormatter *formatter; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _formatter = [[NSDateFormatter alloc] init]; _formatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy"; // twitter date format }); return formatter; } If