nsdate

Get the first day of week without WeekCalendarUnit

余生颓废 提交于 2019-12-01 08:36:59
I would like to get the first day of the week depending on a NSDate. It works fine but I have a warning because WeekCalendarUnit is deprecated. I made some research and I tried to replace WeekCalendarUnit with : static var CalendarUnitWeekday: NSCalendarUnit { get } static var CalendarUnitWeekdayOrdinal: NSCalendarUnit { get } static var CalendarUnitWeekOfMonth: NSCalendarUnit { get } static var CalendarUnitWeekOfYear: NSCalendarUnit { get } But I don't have the same result. Here is my junk of code : var date = NSDate() dateFormatter.dateFormat = "dd/YY" let calendar = NSCalendar

How to count unique dates of CoreData objects?

亡梦爱人 提交于 2019-12-01 08:22:50
问题 I need a proper way to count how many unique days there are in CoreData objects with a property of type NSDate. For example, I have the following: <Object>.date = "2014-05-15 21:29:12 +0000"; <Object>.date = "2014-05-15 21:49:34 +0000"; <Object>.date = "2014-05-16 13:29:23 +0000"; <Object>.date = "2014-05-16 20:49:50 +0000"; <Object>.date = "2014-05-16 22:01:53 +0000"; <Object>.date = "2014-05-20 03:32:12 +0000"; <Object>.date = "2014-05-20 12:45:23 +0000"; <Object>.date = "2014-05-20 14:15

uilocalnotification is not firing at exact time

血红的双手。 提交于 2019-12-01 08:21:53
I want to implement uilocalnotification in my app. but the problem is that it is not firing at the exact time. it is firing after 30 - 40 secs from the given firing time. Is there something I am missing or this is a common think in UILocalNotification . Thanks UILocalNotification is designed for things that are happening far in the future so an error of 30 seconds would be OK (i.e. if I had a meeting at 15:00 then telling me at 15:00:30 wouldn't be a problem :) If you want more accuracy than that you will need to keep your app running and use an NSTimer. Jazzmanouch I know this is an old

NSDateFormatter issue with date format in iOS 8

喜夏-厌秋 提交于 2019-12-01 07:55:42
I have an NSDateFormatter which I use to format an NSDate into a string. The following format does not work: ddMMyyyy_hhmmss_SSS. When I try to format an NSDate I get the following output: 18092014_08:49:03,638, which has a colon and a comma I didn't specify in the format. Note that in iOS 7 I never had this kind of problem. This is the code I'm using: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat: @"ddMMyyyy_hhmmss_SSS"]; NSString *dateString = [dateFormat stringFromDate:exportDate]; iOS8 have serious problem with time format imo. I've just resolved a

Swift - Converting JSON date to Swift compatible date

女生的网名这么多〃 提交于 2019-12-01 07:28:11
问题 I am trying to convert a date in which the javascript code is generating the current date using the Date() function. But when I print it out, I am getting nil. my code: let date2 = data?[0] as! String println(date2) var str = "2013-07-21T19:32:00Z" var dateFor: NSDateFormatter = NSDateFormatter() dateFor.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" var Date: NSDate? = dateFor.dateFromString(date2) println(Date) date2 => is printing out 2015-05-15T21:58:00.066Z Date => is printing nil str is just for

Remove year from NSDateFormatterFullStyle string

不打扰是莪最后的温柔 提交于 2019-12-01 07:19:59
问题 I have searched for this question and didn't find a conclusive and elegant solution. Is there anyway to change the NSDateFormatterFullStyleyear to suppress year information. I'm using the code: NSString *dateDescription; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [dateFormatter setTimeZone:gmt]; [dateFormatter setDateStyle:NSDateFormatterFullStyle]; dateDescription = [dateFormatter stringFromDate:date];

Get the first day of week without WeekCalendarUnit

故事扮演 提交于 2019-12-01 06:50:57
问题 I would like to get the first day of the week depending on a NSDate. It works fine but I have a warning because WeekCalendarUnit is deprecated. I made some research and I tried to replace WeekCalendarUnit with : static var CalendarUnitWeekday: NSCalendarUnit { get } static var CalendarUnitWeekdayOrdinal: NSCalendarUnit { get } static var CalendarUnitWeekOfMonth: NSCalendarUnit { get } static var CalendarUnitWeekOfYear: NSCalendarUnit { get } But I don't have the same result. Here is my junk

uilocalnotification is not firing at exact time

混江龙づ霸主 提交于 2019-12-01 06:49:16
问题 I want to implement uilocalnotification in my app. but the problem is that it is not firing at the exact time. it is firing after 30 - 40 secs from the given firing time. Is there something I am missing or this is a common think in UILocalNotification . Thanks 回答1: UILocalNotification is designed for things that are happening far in the future so an error of 30 seconds would be OK (i.e. if I had a meeting at 15:00 then telling me at 15:00:30 wouldn't be a problem :) If you want more accuracy

format a NSDate to DDMMYYYY?

China☆狼群 提交于 2019-12-01 06:39:07
I have to send a DDMMYYY date from a Date to communicate with an API. NSDateComponents *dateComponents; NSCalendar *gregorian; NSDate *date; gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; dateComponents = [[NSDateComponents alloc] init]; self.date = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0]; Do I have to use the [dateComponents day] and so on? is there some method that can help me to performing that task like in PHP? Try this NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@

iOS one month from current Date.

妖精的绣舞 提交于 2019-12-01 06:39:07
I'm trying to get one month from the current date. Below is what I have and it is returning: 4027-09-24 16:59:00 +0000 . currentDate is right. What's going on? // Get todays date to set the monthly subscription expiration date NSDate *currentDate = [NSDate date]; NSLog(@"Current Date = %@", currentDate); NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit | NSDayCalendarUnit | NSYearCalendarUnit fromDate:currentDate]; dateComponents.month = dateComponents.month + 1; NSDate *currentDatePlus1Month = [[NSCalendar currentCalendar] dateByAddingComponents