nsdate

Getting human readable relative times and dates from a unix timestamp?

感情迁移 提交于 2019-12-30 09:53:14
问题 Starting with a unix timestamp like 1290529723, how would I (assuming gmt) get the information on whether it is: today (if so, what time) in the last seven days (if so, which day ... mon, tues etc?) older than a week (if so, how to output in dd/mm/yy format?) I need this for a list of messages like the iPhone's Mail app, where date/times are shown relative to the current date and time, like so: 15:45 Yesterday Sunday Saturday 10/10/10 etc 回答1: It takes a bit of fiddling to get a solution that

How to convert server response date to local timezone?

冷暖自知 提交于 2019-12-30 07:32:32
问题 In api call response I'm getting dates in different timezone. I want to convert it to user's local timezone plus user can select any timezone from the list of ios timezone. This is all local. We would never be sending selected user timezone to server. And while making any api call lets say i am creating an event with selected start date in a picker. I should send it global timezone not with the user selected timezone because it is local to the app. Currently I am changing defaultTimeZone on

SWIFT: How do I add hours to NSDate object

对着背影说爱祢 提交于 2019-12-30 04:39:21
问题 I generate a NSDate object from string. let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT") let stringToDate = dateFormatter.dateFromString(dateFromService) // 2015-07-20 12:00:43 +0000 I get this string value from webserver. I need to modify for personal device timezone. Want to add hours this stringToDate object but not work var addHours : Int = 2 // 2 hours will be added var newDate = stringToDate

Objective-C, How can I get the current date in UTC timezone?

筅森魡賤 提交于 2019-12-29 10:27:30
问题 I am trying: NSDate *currentDateInLocal = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'"]; NSString *currentLocalDateAsStr = [dateFormatter stringFromDate:currentDateInLocal]; NSDateFormatter * dateFormatter2 = [[NSDateFormatter alloc] init]; NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; [dateFormatter2 setTimeZone:timeZone]; [dateFormatter2 setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'

Swift - check if a timestamp is yesterday, today, tomorrow, or X days ago

坚强是说给别人听的谎言 提交于 2019-12-29 10:21:31
问题 I'm trying to work out how to decide if a given timestamp occurs today, or +1 / -1 days. Essentially, I'd like to do something like this (Pseudocode) IF days_from_today(timestamp) == -1 RETURN 'Yesterday' ELSE IF days_from_today(timestamp) == 0 RETURN 'Today' ELSE IF days_from_today(timestamp) == 1 RETURN 'Tomorrow' ELSE IF days_from_today(timestamp) < 1 RETURN days_from_today(timestamp) + ' days ago' ELSE RETURN 'In ' + days_from_today(timestamp) + ' ago' Crucially though, it needs to be in

Converting String to NSDate Giving Wrong Date

白昼怎懂夜的黑 提交于 2019-12-29 02:06:32
问题 I have a String that I converted using stringFromDate and now I'm trying to convert it back, however when the UIPicker starts, it's giving me the wrong day let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd MMM YYYY" print(birthday) // logs 15 Jan 1992 let date = dateFormatter.dateFromString(birthday) self.datePicker.setDate(date!, animated: true) I tried hardcoding "15 Feb 1992" but still the same result. The date on UIDatePicker shows 22 Dec 1991 on Start. If I use

NSDateFormatter dateFromString Always Returns nil

六月ゝ 毕业季﹏ 提交于 2019-12-28 06:31:06
问题 I want to apologize ahead of time for asking a repeat question, but none of the other solutions have worked for me yet. Every time I try to pass a date string to the dateFromString function I get nil. I haven't read anywhere that things have changed since the iOS 7 update, but I am current on updates if that makes a difference on whether or not this still works the same way. This is the code I'm using to create the date from string: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]

NSDate: Get precise time independent of device clock? [duplicate]

流过昼夜 提交于 2019-12-28 03:01:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I locally detect iPhone clock advancement by a user between app runs? Is there a way to determine the actual time and date in iOS (not the time of the device) Is there a clock in iOS that can be used that cannot be changed by the user Brief I am working with an auto-renewable subscription-based app. When the app receives the latest receipt from Apple, it stores the expires_date_ms key in NSUserDefaults .

NSDate: Get precise time independent of device clock? [duplicate]

天涯浪子 提交于 2019-12-28 03:01:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I locally detect iPhone clock advancement by a user between app runs? Is there a way to determine the actual time and date in iOS (not the time of the device) Is there a clock in iOS that can be used that cannot be changed by the user Brief I am working with an auto-renewable subscription-based app. When the app receives the latest receipt from Apple, it stores the expires_date_ms key in NSUserDefaults .

Core Data Predicate Date Comparison

99封情书 提交于 2019-12-28 02:39:26
问题 Im trying to fetch all the objects in an entity matching a user selectedDate (it's an NSDate). The Core Data code is fine but my predicate keeps returning 0 results, the dates are the same in the database as the user is selecting. How should the selectedDate be compared with a date from an entity using a predicate? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(eDate = %@)", selectedDate]; 回答1: Your predicate looks to be fine. The reason you're finding zero result are returned