nsdate

Setting NSDate in a “TimePicker” with 24 - 12 hours format xcode

假装没事ソ 提交于 2019-12-01 01:55:55
I'm working with some NSDate objects, and well, I use my iPhone with 24 hrs format, so when I was testing my app, everything went fine, but, one of my friends tried the app on his iPhone, but he uses 12hrs format, after some research I found out that the problem was the date, and I have no idea why I use this to set a date picker and a time picker, so I read some values from a database (yes, I've checked the values and they are correct, it is not a value-issue), so all this data is formatted and put together as a NSDate, then, I set the date picker and time picker with this date I just created

Cocoa get first day in week

萝らか妹 提交于 2019-12-01 01:39:38
How to get the first day of a week for a date this seems more easy at it is, since : when the week starts with sunday, i need to get back the sunday date if it starts on monday, i need to get the monday date the input date is any date in week with time... i tried several approaches, but the edge case make it difficould i made a function, which however doesn't work in 100% (not sure about the [components setDay: -weekday + 2];) - (NSDate *)firstDateOfWeek { NSCalendar * calendar = [NSCalendar currentCalendar]; NSDateComponents *weekdayComponents = [calendar components:(NSDayCalendarUnit |

Objective C: Sort Two Dimensional Array

*爱你&永不变心* 提交于 2019-12-01 01:27:22
I have an array of arrays. The contained array's first elements are all NSDate objects. I would like to sort the array containing the arrays in order from most recent to least. For some reason, the below sorting algorithm results in an infinite loop. Can anyone help me out? Thank you. Best...SL //array is the array containing all of the other arrays(that have NSDates as their first elements) //temp is the new array being added to the end of the array, to later be sorted into the correct position. [array addObject:temp]; NSMutableArray *tempArray; for (int i=0; i<[array count]; i++) { NSDate

Calculating the age of a person using two NSDates

你说的曾经没有我的故事 提交于 2019-12-01 01:19: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 | NSMonthCalendarUnit; NSDateComponents *components = [calendar components:units fromDate:dob toDate:now

How to get a NSDATE from UIImage?

大城市里の小女人 提交于 2019-12-01 00:36:24
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? } Greg If you are referring to EXIF metadata in the image (which includes date information), you can see this question for information on how to access it: How to access photo EXIF

Convert NSString to NSDate [duplicate]

廉价感情. 提交于 2019-11-30 22:43:06
Possible Duplicate: Converting NSString to NSDate (and back again) I make a request to the flickr api and it returns me the date in the following format "2013-02-01T06:25:47Z" How do i convert this into NSDate format?? Madhu It's a simple one, converting NSString to NSDate we use NSDateformatter using dateFromString method. We need to provide the Dateformatter style with existing style for NSString NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *date = [dateFormatter dateFromString:@"2013-02-01T06:25:47Z"];

Split NSDate into year month date

こ雲淡風輕ζ 提交于 2019-11-30 22:12:59
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 ? 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 = [components day]; Alsois there any direct way of comparing the years ? not built in. But you could write a

How do I subclass NSDate?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 21:51:52
I first time tried to subClassed an NSDate to give it 2 methods that I need. Compiles fine, but in runtime I try to access it I get an error. Lets say I just want the current date which is unmodified in the subClass: [myNSDate date]; I get the error -[NSDate initWithTimeIntervalSinceReferenceDate:]: method only defined for abstract class. Define -[myNSDate initWithTimeIntervalSinceReferenceDate:]! what is different? NSD’s answer corect, I’ll just try to reiterate in simple terms. NSDate is not a simple class you could easily subclass. It’s a class cluster , which in short means that when you

Swift - Get local date and time

北战南征 提交于 2019-11-30 21:46:10
问题 How can I get local date and time in Swift? let last_login = String(NSDate.date()) 回答1: update: Xcode 8.2.1 • Swift 3.0.2 You can also use the Date method description(with locale: Locale?) to get user's localized time description: A string representation of the Date, using the given locale, or if the locale argument is nil, in the international format YYYY-MM-DD HH:MM:SS ±HHMM, where ±HHMM represents the time zone offset in hours and minutes from UTC (for example, “2001-03-24 10:45:32 +0600”)

dateWithTimeIntervalSince1970 not returning correct date

僤鯓⒐⒋嵵緔 提交于 2019-11-30 21:40:18
I have the following method below that is meant to retrieve and convert a unixTimeStamp from an API call to a NSDate object that I can easily manipulate and use. For some reason, this returns wrong values. An example would be when the unixTimeStamp is 1385152832, the date SHOULD be Fri, 22 Nov 2013 20:40:31 GMT November 22, 2013 at 3:40:31 PM EST but instead spits out: 45852-09-07 08:13:52 EST. Does anyone know why this would happen? -(NSDate *)messageDate { NSTimeInterval unixTimeStamp = [[self messageDateString] doubleValue]; NSDate *messageDate = [NSDate dateWithTimeIntervalSince1970