nsdate

How to convert MySQL datetime to NSDate?

旧巷老猫 提交于 2019-12-01 11:29:48
MySQL returns this datetime: 2014-05-07T16:58:44.000Z How, with what datetime format I can create NSDate ? I far as I found this, but it does not work: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; NSDate *date = [df dateFromString: valueStr]; Your format string is close, but you want to specify the milliseconds with SSS , too: [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSX"]; Also, the Z in your date string stands for "Zulu" (i.e. GMT/UTC), so your dateFormat should use Z or X without quotes so that it correctly parses the string

How to count unique dates of CoreData objects?

穿精又带淫゛_ 提交于 2019-12-01 11:17:03
I need a proper way to count how many unique days there are in CoreData objects with a property of type NSDate. For example, I have the following: <Object>.date = "2014-05-15 21:29:12 +0000"; <Object>.date = "2014-05-15 21:49:34 +0000"; <Object>.date = "2014-05-16 13:29:23 +0000"; <Object>.date = "2014-05-16 20:49:50 +0000"; <Object>.date = "2014-05-16 22:01:53 +0000"; <Object>.date = "2014-05-20 03:32:12 +0000"; <Object>.date = "2014-05-20 12:45:23 +0000"; <Object>.date = "2014-05-20 14:15:50 +0000"; <Object>.date = "2014-05-20 20:20:05 +0000"; In this case, the result must be 3 because there

Does File Attribute contain millisecond? Objective-C

给你一囗甜甜゛ 提交于 2019-12-01 10:36:38
I would like to get milliseconds from creation time of file attribute When I get file attribute, I use NSDateFormatter to convert file creation time (NSDate) to NSString. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SS: A"]; ss --> seconds SS --> should be millisecond A --> milliseconds of the date I get 00 for SS and get 54487000 for A. I notice that the last three digits are always zero for NSDate come from file attribute of any files. But when I use the same formatter with the NSDate come from [NSDate date], the last three digits are not zero for A, and SS digit is not always zero.

Does File Attribute contain millisecond? Objective-C

拜拜、爱过 提交于 2019-12-01 10:07:07
问题 I would like to get milliseconds from creation time of file attribute When I get file attribute, I use NSDateFormatter to convert file creation time (NSDate) to NSString. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SS: A"]; ss --> seconds SS --> should be millisecond A --> milliseconds of the date I get 00 for SS and get 54487000 for A. I notice that the last three digits are always zero for NSDate come from file attribute of any files. But when I use the same formatter with the NSDate

GMT to Local Time Conversion with Daylight Saving Time change

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 09:51:57
问题 From server I'm receiving GMT time structure(user defined structure), using that I want to convert it into local time, I have done it by filling the NSDatecomponent with the structure received, and then I have used date formattter to get date from it, everything works fine except one case. If the GMT time is after Nov 3 (Daylight Saving Time change in US) formatter is producing 1 hour time difference. for eg: If the intended time is for Nov-3 ,4 PM, after conversion from GMT to local its

dateFromString return nil after change 24 hour

北战南征 提交于 2019-12-01 09:50:42
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init]; [timeFormat setDateFormat:@"hh:mm a"]; NSDate* sourceDate = [timeFormat dateFromString:@"19/11/2010 12:00 am"]; if(sourceDate==nil) { NSLog(@"source date nil"); } I'm using 24 hour setting in iPhone. After I change to 24 hour setting, datefromstring always return nil. I rechange to 12 hour format, it's working again. Why ? The locale needs to be set to avoid being affected by the 24-hour setting change. The format also has to match the input string (which in your example includes the date): NSDateFormatter *timeFormat = [

Calling a Method at NSDate

女生的网名这么多〃 提交于 2019-12-01 09:48:46
问题 I'm trying to call a method at a certain time and date (using an NSDate ) but I can't work out how to do it. I don't want to use NSTimer because that becomes paused when the app goes into the background or is closed. I don't want to run one in the background either because this only solves half of the problem and is a wasteful way of doing it in my opinion. I thought that if I could fire a method at an NSDate in the future, when the app is opened again I can see if the current date has passed

How to check whether the date & time of a limit overlaps another limit or not?

北慕城南 提交于 2019-12-01 09:33:01
问题 I want to check whether the date limit* (Ex:- 22/07/2013 2:30PM -22/07/2013 8:30PM ) * comes with in another time limit* (Ex:- 22/07/2013 4:30PM -22/07/2013 6:30PM ) * or not. I am completely new to this concept. Can anyone please tell me how to do this. Any help will be highly appreciated Below is the code I tried: - (void)viewDidLoad { [self isDateInterval:@"8/1/2013 8:30am" and:@"8/1/2013 8:40am" fallsWithin:@"8/1/2013 8:30am" and:@"8/1/2013 8:55am"]; [super viewDidLoad]; } -(BOOL

Convert date to timestamp in iOS

耗尽温柔 提交于 2019-12-01 09:27:27
How do you convert any given date to milliseconds? For example, 2014-01-23 to timestamp conversion. NSDate *date = [dateFormatter dateFromString:@"2014-01-23"]; NSLog(@"date=%@",date); NSTimeInterval interval = [date timeIntervalSince1970]; NSLog(@"interval=%f",interval); NSDate *methodStart = [NSDate dateWithTimeIntervalSince1970:interval]; [dateFormatter setDateFormat:@"yyyy/mm/dd "]; NSLog(@"result: %@", [dateFormatter stringFromDate:methodStart]); Output result: 1970/30/01 Have it a try. "mm" stands for minute while "MM" stands for month. NSDateFormatter * dateFormatter = [[NSDateFormatter

iPhone NSDate eg. next Friday

最后都变了- 提交于 2019-12-01 08:50:24
I want to create a function which results the date of next Friday but I have no plan how to do it. Has anyone a good hint to me ? E.g. Get current date using NSDate, then use 'components>fromDate:' from NSCalendar to get the NSDateComponents, then add the time difference to next Friday and create a new NSDate and Bob's is your uncle. Here is my working solution for getting the next 5 Sundays in Gregorian calendar: self.nextBeginDates = [NSMutableArray array]; NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]]; int