nsdate

get total hours from nsdate

一世执手 提交于 2019-12-25 14:09:44
问题 I'm just looking for a method that calculates the total hours from nsdate (does the same as the TotalHours method in .net) example : 11:30:30 -> 11.5 hours Thanks in advance, 回答1: Get the hour and minute separated with NSDateComponents . NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; Then use

get total hours from nsdate

风格不统一 提交于 2019-12-25 14:09:36
问题 I'm just looking for a method that calculates the total hours from nsdate (does the same as the TotalHours method in .net) example : 11:30:30 -> 11.5 hours Thanks in advance, 回答1: Get the hour and minute separated with NSDateComponents . NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; Then use

get total hours from nsdate

最后都变了- 提交于 2019-12-25 14:09:06
问题 I'm just looking for a method that calculates the total hours from nsdate (does the same as the TotalHours method in .net) example : 11:30:30 -> 11.5 hours Thanks in advance, 回答1: Get the hour and minute separated with NSDateComponents . NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; Then use

NSDate which is returned is incorrect

白昼怎懂夜的黑 提交于 2019-12-25 08:03:20
问题 I am build a function to get the date for the Chinese new year from the date which is passed from a datePicker. the convertDateFormater converts a string formatted date to a date object. the date which i get back is Returned date = "03-Feb-2030" for the year "1970-05-22" but if i run the current date with "NSDate() as Date" i get the right output. for the year 2016. func convertDateFormater(date: String) -> Date { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd"/

Firebase 2.0 - Store Date and Timezone

前提是你 提交于 2019-12-25 07:35:06
问题 I need to store the date that something was created in the firebase database for a friend request, how can i store a date in firebase that i can work out how long ago since this date something happened. I would just store an NSDate in there but then what about timezones? I dunno if firebase has something like Parse had where it would store date created and timezone automatically so you could read it from the server? 回答1: You need to set it up by yourself ! I use this code to do the timestamp.

Conversion of NSString to NSDate failing

前提是你 提交于 2019-12-25 07:23:44
问题 I have the following piece of code.. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/YYYY HH:mm"]; NSString *dateString = @"10/27/2012 18:00"; NSDate *parsedDate = [dateFormatter dateFromString:dateString] ; NSLog(@"Parsed Date.. %@",[parsedDate description]); I am getting the NSLog statement as Parsed Date.. 2011-12-25 00:00:00 +0000 . I would appreciate any help in resolving this. I just want to convert that NSString to its NSDate

Swift Format Date

孤街醉人 提交于 2019-12-25 04:44:12
问题 This is probably really simple, I have tried lots of different methods but it doesnt seem to work. I have the following date format in a text field: Saturday, 2 January 2016 12:00 held as: var str = "\(dobTextField.text!)" I would like to convert the string above into the format: YYYY-mm-dd any help would be much appreciated! 回答1: Check this : let str = "Saturday, 2 January 2016 12:00" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "EEEE, d MMMM yyyy HH:mm" dateFormatter

Convert NSDates from one calendar to another

混江龙づ霸主 提交于 2019-12-25 04:02:59
问题 There are lots of questions with the same title but none has answered my question. I want to be able to convert a NSString that represents Islamic calendar to a NSDate that displays that date in Gregorian calendar. This is the code that i have but it still returns the NSDate in Islamic Calendar. - (NSDate*) convertToNSDateFromString : (NSString *)dateString : (NSString *)dateFormat { //Format the Calendar NSDateFormatter *f = [[NSDateFormatter alloc] init]; NSCalendar *gregorian = [

Convert NSDates from one calendar to another

三世轮回 提交于 2019-12-25 04:01:35
问题 There are lots of questions with the same title but none has answered my question. I want to be able to convert a NSString that represents Islamic calendar to a NSDate that displays that date in Gregorian calendar. This is the code that i have but it still returns the NSDate in Islamic Calendar. - (NSDate*) convertToNSDateFromString : (NSString *)dateString : (NSString *)dateFormat { //Format the Calendar NSDateFormatter *f = [[NSDateFormatter alloc] init]; NSCalendar *gregorian = [

Core data fetch predicate for NSDate

孤街醉人 提交于 2019-12-25 03:17:09
问题 I have entity with two NSDate properties: @property NSDate *startTime; @property NSDate *endTime; I use it for creating the point events and the duration events. So, for the point events endTime can be equal to nil. And i want to fetch all entities with restriction: startTime >= minDate && endTime <= maxDate But NSPredicate like: NSDate *startTime = [[NSUserDefaults standardUserDefaults] objectForKey:@"firstBound"]; NSDate *endTime = [[NSUserDefaults standardUserDefaults] objectForKey:@