nsdate

NSDate between two given NSDates

偶尔善良 提交于 2019-11-26 16:55:46
问题 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. 回答1: This isn't perfect, but

NSDateFormatter and Time Zone issue?

徘徊边缘 提交于 2019-11-26 16:44:40
问题 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

Creating an NSDateFormatter in Swift? [closed]

£可爱£侵袭症+ 提交于 2019-11-26 16:27:16
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . 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

get time between two times of the day

烂漫一生 提交于 2019-11-26 16:19:14
问题 I've already tried with NSDate but with no luck. I want the difference between for example 14:10 and 18:30. Hours and minutes. I Hope you can help me shouldn't be that complicated :) 回答1: There's no need to calculate this by hand, take a look at NSCalendar . If you want to get the hours and minutes between two dates, use something like this: NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSUInteger unitFlags = NSHourCalendarUnit |

Convert ISO 8601 to NSDate

穿精又带淫゛_ 提交于 2019-11-26 16:06:33
问题 I have a timestamp coming from server that looks like this: 2013-04-18T08:49:58.157+0000 I've tried removing the colons, I've tried all of these: Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset? Why NSDateFormatter can not parse date from ISO 8601 format Here is where I am at: + (NSDate *)dateUsingStringFromAPI:(NSString *)dateString { NSDateFormatter *dateFormatter; dateFormatter = [[NSDateFormatter alloc] init]; //@"yyyy-MM-dd'T'HH:mm:ss'Z'" -

Relative string from NSDate

一世执手 提交于 2019-11-26 16:05:17
问题 Does anyone know of a library or something that will convert an NSDate into strings like the examples below? 1 hour ago yesterday last Thursday 2 days ago last month 6 months ago last year 回答1: NSDateFormatter will do a great deal of what is mentioned above by using setDoesRelativeDateFormatting: on an instance. From there, you can control the formatting using the date style and the time style to fine tune it to your needs. If that doesn't get you what you need then check out

UIDatePicker, setting maximum and minimum dates based on todays date

走远了吗. 提交于 2019-11-26 15:49:45
问题 If I have a UIDatePicker, and I wish to set the minimum and maximum date range to be between thirty years ago and thirty years in the future, how would I set that up? 回答1: Not tested, but you probably want something like this. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *currentDate = [NSDate date]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setYear:30]; NSDate *maxDate = [calendar dateByAddingComponents:comps

Truncate NSDate (Zero-out time)

谁都会走 提交于 2019-11-26 15:48:38
问题 I want to generate a new NSDate with 0 hours , 0 minutes , and 0 seconds for time. The source date can be any random NSDate . Is there a way to achieve this? The documentation did not help me with this. Example Have: 2010-10-30 10:14:13 GMT Want: 2010-10-30 00:00:00 GMT 回答1: unsigned int flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:flags fromDate:date]; NSDate*

NSTimer not firing when runloop is blocked

允我心安 提交于 2019-11-26 15:48:33
问题 I am just about finished with my app and beta testing found a bug in the stopwatch portion... The stopwatch uses an nstimer to do the counting and has a table for storing laps, but when the lap table is scrolled the watch stops or pauses and does not make up for the lost time. This was stalling was eliminated by using: startingTime = [[NSDate date] timeIntervalSince1970]; to calculate the elapsed time. but I am still using the NSTimer to trigger every 0.1 secs and that means that the

Unexpected value from NSDate

夙愿已清 提交于 2019-11-26 15:33:04
I'm trying to store a time in a date. In this case 1.5 seconds. I store the time in the date like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"mm:ss.SS"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]]; NSDate *date1 = [dateFormatter dateFromString:@"00:01.50"]; But if I look in the debug area I can see that the value of date1 was set to: date1 = (NSDate *) 0x1dd32b30 2000-01-01 01:00:01 CET Could anyone tell me why this is happening? Because there is a mass of question related to NSDate on SO and they all have