nsdate

iOS one month from current Date.

柔情痞子 提交于 2019-12-19 08:54:24
问题 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 =

Convert NSDate to mm/dd/yyyy

Deadly 提交于 2019-12-19 05:18:56
问题 I know this question is similar to others asked, but I can't find where my code is going wrong. I am trying to convert the current date into a mm/dd/yyyy format. Here is what I am using: NSDate *date = [[NSDate alloc]init]; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"mm/dd/yyyy"]; NSLog(@"%@", [formatter stringFromDate:date]); The problem is the month. Every time I run this code, the month is different. For example the first time my

NSDate Min and Max Possible Values

99封情书 提交于 2019-12-19 05:07:03
问题 Anyone know what the minimum and maximum possible values are for an NSDate? 回答1: Use [NSDate distantFuture] and [NSDate distantPast]. 回答2: EDITED Answer: I thought that I'd discovered the minimum date value was 0001-01-01 00:00:00 + 0000 (given my code below) HOWEVER as has been pointed out in the comments below, this is only for the current era (i.e. A.D.). An NSDate value can go lower than this but what you see as a result of an NSLog may not be what you are expecting, so I would recommend

Calculating the age of a person using two NSDates

假如想象 提交于 2019-12-19 04:45:11
问题 My class representing a person has a method to calculate that person's age: @interface Student : NSObject @property (strong) NSDate *dob; // This method will work out the person's age in calendar years - (NSDateComponents*)ageCalculation:(NSDate*)dob; Here is the class implementation file @implementation Student - (NSDateComponents*)ageCalculation:(NSDate*)dob { NSDate *now = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSCalendarUnit units = NSYearCalendarUnit |

How to get a NSDATE from UIImage?

心已入冬 提交于 2019-12-19 04:33:51
问题 How do i get a date or metadata from a UIImage in this case: //UIImagePickerControllerSourceType picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //delegate return - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ // po info in console -> there is no metadata of the image where i can find the date // Has anyone an idea how to get it? } 回答1: If you are referring to EXIF metadata in the image (which includes

Split NSDate into year month date

时光怂恿深爱的人放手 提交于 2019-12-19 03:39:07
问题 If I have a date like 04-30-2006 how can I split and get month, day and year Alsois there any direct way of comparing the years ? 回答1: you have to use NSDateComponents. Like this: NSDate *date = [NSDate date]; NSUInteger componentFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *components = [[NSCalendar currentCalendar] components:componentFlags fromDate:date]; NSInteger year = [components year]; NSInteger month = [components month]; NSInteger day =

App Crashed when device time is in 24 hour format

[亡魂溺海] 提交于 2019-12-19 03:25:42
问题 In my App if IPhone device time is in 12 hour formate then date formatter works correctly but if device time is in 24 hour formate then app crashed. let dateFormatter = NSDateFormatter(); dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle; dateFormatter.dateFormat = "hh:mm a"; var dt1 = dateFormatter.dateFromString(arrSecond.objectAtIndex(n) as! String) 回答1: @Rajan Thanks for giving me idea of NSLocale . I set the dateformatter's

Formatting a DateTime object from .NET into a NSDate for objective-c

心不动则不痛 提交于 2019-12-19 02:40:13
问题 I am working with an API that returns a .NET DateTime object into my iOS application. I'm a little confused at what's going on, the DateTime looks fine when it leaves the API, but when it comes in it goes through JSON and comes in as a string that looks like this: /Date(1303884000000-0600)/ WTF is that and how can I turn it into a NSDate object?? Thanks! 回答1: From Parsing JSON dates on IPhone I found the following function to be perfect: - (NSDate*) getDateFromJSON:(NSString *)dateString { //

Formatting a DateTime object from .NET into a NSDate for objective-c

老子叫甜甜 提交于 2019-12-19 02:39:59
问题 I am working with an API that returns a .NET DateTime object into my iOS application. I'm a little confused at what's going on, the DateTime looks fine when it leaves the API, but when it comes in it goes through JSON and comes in as a string that looks like this: /Date(1303884000000-0600)/ WTF is that and how can I turn it into a NSDate object?? Thanks! 回答1: From Parsing JSON dates on IPhone I found the following function to be perfect: - (NSDate*) getDateFromJSON:(NSString *)dateString { //

How to compare current date to previous date in iphone?

人走茶凉 提交于 2019-12-18 21:56:07
问题 I would like to compare the current date with another date, and if that is date is earlier than the current date, then I should stop the next action. How can I do this? I have todays date in yyyy-MM-dd format. I need to check this condition if([displaydate text]<currentdate) { //stop next action } Here if displaydate is less than todays date then it has to enter that condition. 回答1: NSDate *today = [NSDate date]; // it will give you current date NSDate *newDate = [dateFormatter dateWithString