nsdate

Where is the extra 75 seconds coming from?

北战南征 提交于 2019-12-03 00:55:53
While writing some unit tests on a Julian Day calculator, I found that dates prior to 2nd December 1847 were being initialised incorrectly by NSDate. They appear to have 75 seconds added on. I haven't been able to find anything pointing to that date (which is well after the Gregorian calendar cutoff). Is it a bug or is there a historic calendar adjustment that I've not come across? int main(int argc, const char * argv[]) { @autoreleasepool { NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *dateComps = [NSDateComponents new]; dateComps.year = 1847; dateComps.month = 12;

Converting ex. 2010-09-11T00:00:00+01:00 format to NSDate

不想你离开。 提交于 2019-12-03 00:08:40
I have spent way too much time (over an hour) on what I though would be a two minute task. On the iPhone: NSString * dateString = @"2010-09-11T00:00:00+01:00"; NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssTZD"]; NSDate *date = [formatter dateFromString:dateString]; RESULT: date == nil What am I missing!! (Besides my deadline) Regards, Ken TZD isn't a defined formatter per the unicode spec . The document you've linked to elsewhere was a suggestion someone made to W3C, for discussion only. The unicode standard followed by Apple is

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

。_饼干妹妹 提交于 2019-12-03 00:05:51
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=[[NSDateFormatter alloc]init]; [objDayFotmatter setDateFormat:@"EEEE"]; NSString *objTime=[objTimeFotmatter

iOS - Friendly NSDate format

眉间皱痕 提交于 2019-12-03 00:02:52
I need to display the date of posts in my app to the user, right now I do it in this format: "Fri, 25 May". How would I format an NSDate to read something like "2 hours ago"? To make it more user friendly. NSDateFormatter can't do things like that; you're going to need to establish your own rules. I guess something like: - (NSString *)formattedDate:(NSDate *)date { NSTimeInterval timeSinceDate = [[NSDate date] timeIntervalSinceDate:date]; // print up to 24 hours as a relative offset if(timeSinceDate < 24.0 * 60.0 * 60.0) { NSUInteger hoursSinceDate = (NSUInteger)(timeSinceDate / (60.0 * 60.0))

Calculate time difference in Cocoa

北城余情 提交于 2019-12-02 23:21:31
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 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"HHmmss"]; NSDate *date1 = [dateFormatter dateFromString:@"161500"]; NSDate *date2 = [dateFormatter dateFromString:@"171500"]; NSTimeInterval diff = [date2 timeIntervalSinceDate:date1]; // diff =

Getting current time from timezone, not the system/mobile time

≡放荡痞女 提交于 2019-12-02 22:39:06
问题 Can any one help me to get the current time of the time zone? Say for example if the user has an Indian timezone with mobile i.e. 5.00 PM, but he statically change his mobile time to 5.30 PM, here I need the actual timezone time, not the mobile time which the user changed as per his preference. 回答1: If you need access to the world's clock, contact an NTP server. Go to Cocoapods and find a pod to do that. The example below is for ios-ntp: class ViewController: UIViewController { let

NSInvalidArgumentException, reason: 'Invalid type in JSON write (__NSDate)'

时光怂恿深爱的人放手 提交于 2019-12-02 22:15:21
I'm getting this exception when I try to JSON encode NSDate object.I believe NSDate is not compatible for JSON encoding. but I must encode the date.Any solutions? *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSDate)' Rushi FIrst store your data in NSString. And then convert your string to NSDate. You can refer SO: Converting NSString to NSDate (and back again) NSString to NSDate conversion problem How to convert NSString to NSDate using NSDateFormatter? pradeepa Convert NSDate to NSString and try to encode. - (NSString *)

Creating NSDate object with specific time zone

喜欢而已 提交于 2019-12-02 21:47:49
问题 I've written a method that accepts a NSDate object and should turn it into a NSDate object with EST time zone. The way I've seen other people accomplish this is by using a date formatter to change the date to a string with the specified time zone. The issue is when I try to change that string back to a NSDate object using "dateFromString". - (NSDate*)turnToEST:(NSDate*)date { NSLog(@"turnToEST called with date %@", date); NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

How to check if two NSDates are from the same day [duplicate]

☆樱花仙子☆ 提交于 2019-12-02 21:39:36
This question already has an answer here: Comparing NSDates without time component 16 answers I am working on ios development and I find it really hard to check if two NSDates are from the same day. I tried to use this fetchDateList() // Check date let date = NSDate() // setup date formatter let dateFormatter = NSDateFormatter() // set current time zone dateFormatter.locale = NSLocale.currentLocale() let latestDate = dataList[dataList.count-1].valueForKey("representDate") as! NSDate //let newDate = dateFormatter.stringFromDate(date) let diffDateComponent = NSCalendar.currentCalendar()

Swift: using UIDatePicker as UITextField inputView not updating

我们两清 提交于 2019-12-02 20:35:07
I have a textfield and when it is selected a datepicker pops up instead of a keyboard, but it only updates with todays date the first time. The user changes the date, but the textfield does not continue to update. What is the problem? This is how I call the Datepicker and control the date being inputted into my textfield: @IBAction func dp(sender: UITextField) { var DatePickerView : UIDatePicker = UIDatePicker() DatePickerView.datePickerMode = UIDatePickerMode.Date textfieldjobdate.inputView = DatePickerView DatePickerView.addTarget(self, action: Selector("handleDatePicker"), forControlEvents: