nsdate

How to get Current EST time IOS Swift

你离开我真会死。 提交于 2020-03-02 18:58:40
问题 I need to compare two dates in my app and i have a EST date to compare with current date , but let today = NSDate() returns the date in UTC , how can i get current EST time or convert to EST ? 回答1: The NSDate store the time in absolute moment i.e. No matter in what time zone your date was created when you use compare method of NSDate it will respect the time zone (because time zone was never stored). You can think of NSDate as epoch time which is always calculated from 00:00:00 Coordinated

Date Format - time zone

无人久伴 提交于 2020-02-24 20:55:31
问题 I receive from the server a string with a date that looks like this: "2013-03-29T15:27:00Z". How can I format it and transform it into an NSDate? 回答1: Try this: [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *date = [formatter dateFromString:@"2013-03-29T15:27:00Z"]; 回答2: NSString *departTimeDate = @"2013-03-29T15:27:00Z";

String value not converting to date format

孤人 提交于 2020-02-23 06:46:08
问题 String value not converting to date format. see my code below... { NSString * TempDate = [NSString stringWithFormat:@"%@ %@ %@",Datelbl.text,yearString,TimeLbl.text]; // result is Thursday, November 21 2013 3:05 PM NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat : [NSDateFormatter dateFormatFromTemplate:@"EEEE, MMMM d yyyy hh:mm a" options:0 locale:[NSLocale currentLocale]]]; AppointmentDate = [dateFormatter dateFromString:TempDate];// in .h file

iOS how to call a method on the minute, every minute

大城市里の小女人 提交于 2020-02-05 05:38:37
问题 I mean 12:01:00, 12:02:00 ... In iOS7, I want to call a method when minute of time is changed. In other words, if now is 01:55:47, then I want to call a method at 01:56:00 -> 01:57:00 -> 01:58:00 ... All I found about call a method is just about TimeInterval, but not I want. I've tried this code: NSTimeInterval roundedInterval = round([[NSDate date] timeIntervalSinceReferenceDate] / 60.0) * 60.0; NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:roundedInterval]; NSTimer *timer =

How to get the 'n' weekday of a Date

不羁岁月 提交于 2020-01-30 11:48:11
问题 I need to translate this function into swift. Basically what does it get the 'n' day of the current week. So for example if i use it with NSDate().getWeekDay(0) it gives me Sun 11 Sept, and so on. But seems rangeOfUnit no longer exists in Swift-3. This was my previous implementation in Swift-2 extension NSDate { func getWeekDay(day: Int) -> NSDate { var beginningOfWeek: NSDate? NSCalendar.currentCalendar().rangeOfUnit(NSCalendarUnit.WeekOfYear, startDate: &beginningOfWeek, interval: nil,

How to get the 'n' weekday of a Date

时光总嘲笑我的痴心妄想 提交于 2020-01-30 11:47:25
问题 I need to translate this function into swift. Basically what does it get the 'n' day of the current week. So for example if i use it with NSDate().getWeekDay(0) it gives me Sun 11 Sept, and so on. But seems rangeOfUnit no longer exists in Swift-3. This was my previous implementation in Swift-2 extension NSDate { func getWeekDay(day: Int) -> NSDate { var beginningOfWeek: NSDate? NSCalendar.currentCalendar().rangeOfUnit(NSCalendarUnit.WeekOfYear, startDate: &beginningOfWeek, interval: nil,

How to get the 'n' weekday of a Date

依然范特西╮ 提交于 2020-01-30 11:47:10
问题 I need to translate this function into swift. Basically what does it get the 'n' day of the current week. So for example if i use it with NSDate().getWeekDay(0) it gives me Sun 11 Sept, and so on. But seems rangeOfUnit no longer exists in Swift-3. This was my previous implementation in Swift-2 extension NSDate { func getWeekDay(day: Int) -> NSDate { var beginningOfWeek: NSDate? NSCalendar.currentCalendar().rangeOfUnit(NSCalendarUnit.WeekOfYear, startDate: &beginningOfWeek, interval: nil,

NSDateFormatter - 1 day incorrect?

主宰稳场 提交于 2020-01-30 05:08:12
问题 I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"M/d/yyyy"]; NSDate *date = [dateFormatter dateFromString:@"10/7/2007"]; but when I output the date in an NSLog it has this: NSLog(@"Date:

NSDateFormatter - 1 day incorrect?

拈花ヽ惹草 提交于 2020-01-30 05:07:19
问题 I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"M/d/yyyy"]; NSDate *date = [dateFormatter dateFromString:@"10/7/2007"]; but when I output the date in an NSLog it has this: NSLog(@"Date:

Swift 3: Date vs NSDate?

有些话、适合烂在心里 提交于 2020-01-27 03:51:29
问题 What is the difference between the NS and non NS classes? Particularly NSDate vs Date ? Does NS represent some type of wrapper around the core non NS functionality? 回答1: Swift 3 introduced some new overlay value types for existing Foundation class types, such as Date for NSDate , Data for NSData and some more. The full list and details can be found in SE-0069 Mutability and Foundation Value Types Some of the reasons were Provide proper value semantics, let and var instead of mutable and