nscalendar

Working out the start and end of a day. Swift

蓝咒 提交于 2019-12-08 06:04:01
问题 I have a function to work out the start and end of a week which works as expected. I want to implement another function which works out the start and end of a single day. I have the code below however I get the following error: Type of expression is ambiguous without more context. public class Date { let dateFormatter = NSDateFormatter() let date = NSDate() let calendar = NSCalendar.currentCalendar() func calcStartAndEndDateForWeek(durationOccurance: Double) { print("Calculating start and end

UILocalNotification with repeatInterval set NSWeekdayCalendarUnit doesn't trigger weekly

徘徊边缘 提交于 2019-12-08 05:17:23
问题 I'm trying to setup local notification to repeat weekly. Here's my setup: UILocalNotification* localNotification = [[UILocalNotification alloc] init]; ... localNotification.repeatInterval = NSWeekdayCalendarUnit; In console log: localNotif: {fire date = Friday, April 24, 2015 at 12:27:33 PM Singapore Standard Time, time zone = Asia/Singapore (GMT+8) offset 28800, repeat interval = NSWeekdayCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, April 25

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

Swift displaying the time or date based on timestamp

若如初见. 提交于 2019-12-06 16:43:39
I have an API that returns data including a timestamp for that record. In swift I have the timestamp element loaded and converted into a double and can then convert that into time. I want to be able to return the time if the date of the record is today and return the date if the record is not today. See below: let unixTimeString:Double = Double(rowData["Timestamp"] as! String)! let date = NSDate(timeIntervalSince1970: unixTimeString) // This is on EST time and has not yet been localised. var dateFormatter = NSDateFormatter() dateFormatter.timeStyle = .ShortStyle dateFormatter

Count of a specific weekday occurring between two NSDates [closed]

青春壹個敷衍的年華 提交于 2019-12-06 12:45:54
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . How can I find the count of a specific weekday occurring between two NSDates ? I have searched for quite a while but came up with only solution in which number of total weekdays have been counted, not only the one specific week day. The idea of the following code is to compute the first occurrence of the given weekday after the start date, and then compute the number of weeks remaining to the end date. NSDate

Converting NSDate from a calendar to another

送分小仙女□ 提交于 2019-12-06 06:04:37
I'm having trouble here. Took me hours but no use. Please keep in mind I checked the heck of StackOverFlow for a fix but there isn't any. When I convert the _date Object from Gregorian to Hijri it does not convert. I know that because when I print it it still gives me the Gregorian day. This troubles me because I want to setDate of a UIDatePicker and it's setting it incorrectly because the _date is gregorian and my UIDatePicker object calendar set to setCalendar:_hijriCalendar //DATE SETTING _date = [NSDate date]; _hijriCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSIslamicCalendar

How to get All the sundays in Array of date ios

梦想与她 提交于 2019-12-06 05:39:49
问题 i just want an array who contain all the Mondays in the year in the form of NSDate but in swift. i am using the folowing code in the objective -c but dont know how to user it in swift. NSDate *pickerDate = [NSDate date]; NSLog(@"pickerDate: %@", pickerDate); NSDateComponents *dateComponents; NSCalendar *calendar = [NSCalendar currentCalendar]; dateComponents = [calendar components:NSWeekdayCalendarUnit fromDate:pickerDate]; NSInteger firstMondayOrdinal = 9 - [dateComponents weekday];

In Objective-C, to get the current hour and minute as integers, we need to use NSDateComponents and NSCalendar?

落爺英雄遲暮 提交于 2019-12-06 03:54:59
问题 I'd like to get the current hour and minute as integers. So if right now is 3:16am, I'd like to get the two integers: 3 and 16. But it looks like [NSDate date] will give the number of seconds since 1970, or it can give a string of the current time representation, but there is no easy way to get them as integers? I see a post in Getting current time, but it involved NSDateComponents and NSCalendar ? That's way too complicated... all that was need is something like NSDate *date = [NSDate date];

iOS create date in the future ignoring daylight savings

梦想与她 提交于 2019-12-05 01:42:41
I'm trying to work with dates and create dates in the future, but daylight savings keeps getting in the way and messing up my times. Here is my code to move to midnight of the first day of the next month for a date: + (NSDate *)firstDayOfNextMonthForDate:(NSDate*)date { NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; calendar.timeZone = [NSTimeZone systemTimeZone]; calendar.locale = [NSLocale currentLocale]; NSDate *currentDate = [NSDate dateByAddingMonths:1 toDate:date]; NSDateComponents *components = [calendar components:NSYearCalendarUnit |

How to subtract date components?

爱⌒轻易说出口 提交于 2019-12-05 00:28:00
As today is Friday , which is 6 according to NSCalendar . I can get this by using the following Calendar.current.component(.weekday, from: Date()) How do I get weekday component of Saturday last week, which should be 7 ? If I do Calendar.current.component(.weekday, from: Date()) - 6 . I am getting 0 which is not valid component. Tj3n Try this, you have to get the date first then subtract again from it: var dayComp = DateComponents(day: -6) let date = Calendar.current.date(byAdding: dayComp, to: Date()) Calendar.current.component(.weekday, from: date!) For that first you need to get that date