nsdate

Make a new NSDate by combining two NSDates

白昼怎懂夜的黑 提交于 2019-12-09 10:40:35
问题 I have NSDate* day1 and NSDate* day2 . How can I make a NSDate* day3 by copying only year/month/day from day1 and hour/minute/second from day2? 回答1: unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *comps = [[NSCalendar currentCalendar] components:unitFlags fromDate:day1]; NSDate *day3 = [[NSCalendar currentCalendar] dateFromComponents:comps]; unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; comps = [[NSCalendar

Can't pass Date to NSPredicate(format: …) without “as CVarArg”

一个人想着一个人 提交于 2019-12-09 07:38:22
问题 Is this how I'm supposed to pass a Date to NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer) . let endDate = Date() NSPredicate(format: "endDate == %@", endDate as CVarArg) It looks kinda clumsy, and I suspect I'm doing something wrong. 回答1: The %@ format expect a Foundation object as argument, compare "Predicate Format String Syntax" in the "Predicate Programming Guide". Therefore you have to cast the overlay type Date back to its Foundation counterpart

How to properly convert the Last-Modified header from an HTTP response to an NSDate on iOS

若如初见. 提交于 2019-12-09 04:38:48
问题 I am looking for a fully working solution, one that works with: any iOS locale or timezone any/most HTTP servers Xcode 4.0.2 (see why) Current broken code: NSString lastModifiedString = @"Mon, 06 Jun 2011 12:47:05 GMT"; NSDateFormatter *df = [[NSDateFormatter alloc] init]; //df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"; df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; df.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; df.timeZone = [NSTimeZone

Nsdateformatter returns me day in language of the phone selected. Can it return me only English all the time?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 04:18:12
问题 I am using dateformatter to get days and time in the my application. But I am facing an issue when I change the language of the phone dateformatter returns me day and time of the selected language of the phone due to which my app crashes as we are not supporting multiple languages. Please find the below code snippet: NSDate *date=[NSDate date]; NSDateFormatter *objTimeFotmatter=[[NSDateFormatter alloc]init]; [objTimeFotmatter setDateFormat:@"HH:mm"]; NSDateFormatter *objDayFotmatter=[

Modifying NSDate to represent 1 month from today

不打扰是莪最后的温柔 提交于 2019-12-09 04:08:46
问题 I'm adding repeating events to a Cocoa app I'm working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the following code to modify the date: [NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))] I know how many months have passed since the event was repeated but I can't figure out how to make an NSDate object that represents 1 month/3 months/6 months/9 months into the future. Ideally I want the user to say repeat monthly

How to convert MySQL datetime to NSDate?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 03:22:00
问题 MySQL returns this datetime: 2014-05-07T16:58:44.000Z How, with what datetime format I can create NSDate ? I far as I found this, but it does not work: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; NSDate *date = [df dateFromString: valueStr]; 回答1: Your format string is close, but you want to specify the milliseconds with SSS , too: [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSX"]; Also, the Z in your date string stands for "Zulu

Converting date between timezones swift

徘徊边缘 提交于 2019-12-09 02:40:06
问题 I have a date stored on my online server database which is in GMT . I load the date and convert it to the user's timezone using the following code : if let messagedate = oneitem["timestamp"] as? String { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let date = dateFormatter.dateFromString(messagedate) let source_timezone = NSTimeZone(abbreviation: "GMT") let local_timezone = NSTimeZone.systemTimeZone() let source_EDT_offset = source_timezone?

How to convert date string into format “17 Nov 2010”

▼魔方 西西 提交于 2019-12-09 02:15:36
I have the date that is in format 2010-11-17 .This is of the form NSString . I want to convert this NSString date into format 17 Nov 2010 and display in a label This date is just not the current date but may even be the older dates. So I cant use the [NSDate date] instance to get the date. I tried using NSDateFormatter with the method dateFromString . But it gives me a null value. Here is the code snippet NSString *dates = @”2010-11-16”; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MMM yyyy"]; NSDate *dates1 = [dateFormatter dateFromString

NSPredicate- For finding events that occur between a certain date range

冷暖自知 提交于 2019-12-09 00:14:04
问题 This is a little more complicated then just NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate >= %@ AND endDate <= %@", startDay,endDay]; I'm building a calendar app and I need to pull events out of my core data store that occur on a given day. However, it's possible for an event to start/end on a different day then the day I'm trying to display, e.g. My Date Range (Start = 2011-12-02 00:00:00 to End = 2011-12-02 23:59:59) An Event (Start = 2011-12-01 23:00:00 to End =

How can i compare two dates (NSDate) in Swift 3 and get the days between them?

自作多情 提交于 2019-12-08 18:41:27
问题 How can I compare two dates in Swift 3? I found many solutions for other Swift versions, but they doesn't work for me. let clickedDay:String = currentcell.DayLabel.text! let currentDate = NSDate() let currentDay = "" //want the current day let dateFormatter = DateFormatter() var dateAsString = "" if Int(clickedDay)! < 10 { dateAsString = "0" + clickedDay + "-11-2016 GMT" } else { dateAsString = clickedDay + "-11-2016 GMT" } dateFormatter.dateFormat = "dd-MM-yyyy zzz" let clickedDate =