nsdate

NSDateFormatter returns nil for @“dd-MM-yy” in iOS 3.0

ぃ、小莉子 提交于 2019-12-04 14:33:38
问题 I have this part of code: NSDate *date =nil; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; [dateFormatter setDateFormat:@"dd-MM-yy"]; date = [dateFormatter dateFromString:inString]; [dateFormatter release]; It works perfectly fine, as expected in iOS 4.0. But the same code doesnt in 3.0. The string which I am getting, is like "12-Nov-10" and this is contained in inString pointer. The date formatter returns nil if the

Comparing NSDate

可紊 提交于 2019-12-04 14:20:24
I would like to compare two NSDates however every date shows as being "Earlier" than todaysDate . Any ideas? let compareResult = self.todaysDate.compare(self.date) if compareResult == NSComparisonResult.OrderedDescending { println("Today is later than date2") } else { println("Future") } To get "todaysDate" let todaysDate = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitMonth | .CalendarUnitYear | .CalendarUnitDay, fromDate: todaysDate) let hour = components.hour let minutes = components.minute

How to set the first day of current week to Tuesday in Swift?

孤人 提交于 2019-12-04 14:18:23
问题 How to set the first day of current week to Tuesday in Swift 3? The schedule will update every Tuesday so the first day have to start from Tuesday. and then display on label : thisWeekDate.text! = "\(first day of current week) - \(last day of current week)" Full code. let today = NSDate() let nextTue = Calendar.current.date(byAdding: .day, value: 6, to: today as Date) let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd" let todayString = formatter.string(from: today as Date)

Is there a daylight savings check in Swift?

∥☆過路亽.° 提交于 2019-12-04 13:56:58
I need to check to see if the current date is during daylight savings time. In pseudocode that would be like this: let date = NSDate() if date.isDaylightSavingsTime { print("Success") } I haven't been able to find the solution to this anywhere on the internet. An NSDate alone represents an absolute point in time. To decide if a date is during daylight savings time or not it needs to be interpreted in the context of a time zone . Therefore you'll find that method in the NSTimeZone class and not in the NSDate class. Example: let date = NSDate() let tz = NSTimeZone.localTimeZone() if tz

Convert an NSDate to a Unix timestamp using a particular time zone

喜欢而已 提交于 2019-12-04 12:13:15
I am trying to get the Unix timestamp using a particular time zone (not necessarily the same time zone as the system) I tried this : NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSTimeZone *gmt = [NSTimeZone timeZoneWithName:@"Australia/Melbourne"]; [dateFormatter setTimeZone:gmt]; NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]]; NSDate *curdate = [dateFormatter dateFromString:timeStamp]; int unix_timestamp = [curdate timeIntervalSince1970]; This should apparently, give the Unix timestamp

Which is this NSDateFormatter style Friday, December 18th

雨燕双飞 提交于 2019-12-04 11:16:54
I want to know which is this date format Friday, December 18th and also is this standard date format or i have to some hard work to get this. Thanks. I don't think the th is possible to achieve via formatters. Although you can do it like this: NSDate *today = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"EEEE, MMMM d"]; NSString *dateString = [dateFormat stringFromDate:today]; NSCalendar *cal = [NSCalendar currentCalendar]; unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *dtComp =

Get time from remote server for ios app

时光毁灭记忆、已成空白 提交于 2019-12-04 10:38:35
I would like to know how my iOS app can get the datetime from a distant server (NTP ? Other..?), and not with local iPad datetime ; and transform it on NSDate. Thanks https://github.com/jbenet/ios-ntp seems to be a NTP framework for iOS which gives you [NSDate networkDate]; 来源: https://stackoverflow.com/questions/10851161/get-time-from-remote-server-for-ios-app

iPhone How to get image back from NSData

馋奶兔 提交于 2019-12-04 09:47:04
In my iPhone App I am storing image into NSData by UIImage *image =imageView.image; NSData *myData = UIImagePNGRepresentation(image); But How to get back "image" from " NSData " and I can display it again into in to UIImageView . Please Help and Suggest, Thanks. have you tried +[UIImage imageWithData:] ? UIImage *img=[UIImage imageWithData:data]; [yourImageView setImage:img]; 来源: https://stackoverflow.com/questions/4655174/iphone-how-to-get-image-back-from-nsdata

Compare two time values in ios? [duplicate]

安稳与你 提交于 2019-12-04 09:29:41
问题 This question already has answers here : Comparing time and date in objective C (2 answers) Closed 5 years ago . In my app i want to check whether the current time is before or after the time saved in a variable. like my time1 is time1=@"08:15:12"; and my time2 is time2=@"18:12:8"; so i wanna compare between time1 and time2.Currently these variables are in NSString Format. Following are the code used to get time,and i dont know how to compare them. CODE: NSDateFormatter *dateFormatter = [

Calculate time difference in Cocoa

杀马特。学长 韩版系。学妹 提交于 2019-12-04 08:27:52
问题 I have got two timevalues in the format: %H%M%S (E.G.161500) These values are text-based integers. Is there a simple function in Cocoa that calculates the difference between these two integers using a 60 seconds and minutes scale? So if time 1 = 161500 time 2 = 171500 timedifference = 003000 回答1: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"HHmmss"]; NSDate *date1 = [dateFormatter dateFromString:@"161500"]; NSDate *date2 =