nsdate

Create NSDate from 24h NSString return null

折月煮酒 提交于 2019-12-13 08:57:28
问题 I have NSString in 24h format like that: NSString *a = @"10:00"; NSString *b = @"23:59"; How can I get NSDate with NSString b? I using: + setDateFormat: @"HH:mm" ==> It's work both for a and b when phone setting is 24h. + setDateFormat: @"hh:mm" ==> It's only work for a when phone setting is am/pm. My full code, with self.timeInit is NSString with 24h format: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"HH:mm"]; NSDate *date = [dateFormat

How to reduce few minutes for current date in Swift 2.0 [duplicate]

白昼怎懂夜的黑 提交于 2019-12-13 08:50:32
问题 This question already has answers here : How to add minutes to current time in swift (9 answers) Closed 4 years ago . How can I reduce 5 or 10 minutes from current time and then store it as date format in Swift 2.0 ? let now = NSDate() var reducedTime = ???? \\ Here I want 10 minutes reduced from current time. If current time is 02:20:00, then reducedTime should be 02:10:00 How can I do this in a simplest way ??? 回答1: You can use calendar method dateByAddingUnit and subtract 10 minutes fro

NSDate early by 1 hour?

断了今生、忘了曾经 提交于 2019-12-13 08:25:53
问题 I am using the following code to set a date object: NSDate *date = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date]; [components setHour: 18]; [components setMinute: 00]; [components setSecond: 00]; reminderDate = [gregorian dateFromComponents: components]; However, when I NSLog reminderDate I get the following output: Time: 2012-08-29 17:00:00 +0000

Converting string to date iOS

你说的曾经没有我的故事 提交于 2019-12-13 08:02:39
问题 I have the following string: 01/27/2016 11:00:00 And I am passing it to this method: -(NSDate*)dateFromString:(NSString*)dateString format:(NSString*)format { NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yy, HH:mm:ss"]; [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; NSLog(@"%@", [dateFormatter dateFromString:strToConvert]); } and it is returning nil . Not sure what I am doing wrong here. Edit:This only seems to be happening on

NSDateFormatter dateFromString returning wrong date

流过昼夜 提交于 2019-12-13 07:37:20
问题 Quick question. I have a string date: example var dateString = "17-02-2015" I use: var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy" var newDate = dateFormatter.dateFromString(dateString) And I get the output: 2015-01-16 23:02:00 +0000 Why am I missing a day? Is it because of the time zone? (I am at +1, and in the date the timezone is 0?). I also tryed setting the time zone: dateFormatter.locale = NSLocale.currentLocale() dateFormatter.timeZone = NSTimeZone

Calculate time elapsed between pressing the same button twice

本秂侑毒 提交于 2019-12-13 07:17:29
问题 I've tried all the time calculating examples I found on this site but somehow I'm getting 0 as value every time. I'm new to IOS and the NSDate is giving me a run for it's money :) I want to record time A when I press button "startStop", and then record time B when I press it again. Pressing it a second time (deselecting) has to calculate the time elapsed between these 2 dates. So far I have this: -(IBAction)buttonClick { NSDate *startStopDate = [NSDate alloc]; NSDateFormatter *formatter= [

NSTimeInterval seems to be wrong for last day of the given month- iOS

↘锁芯ラ 提交于 2019-12-13 05:41:18
问题 In my local database, I have a list of NSTimeInterval values saved. I have to find out and fetch all records available in a given Month. The only problem is in fetching records for last day of the given month seems to be unavailable. Lets say given month is December so I have to fetch all the records from 1st Dec to 31st Dec (Till 11:59PM) I am using following implementation: [self.dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *startDate = [self.dateFormatter dateFromString:@"1-12-2012"]

NSDateFormatter fails parsing three letter abbreviation of German month March/June/Jul

守給你的承諾、 提交于 2019-12-13 05:38:57
问题 I have a number of German dates in the format of "10.Feb.2016", i.e. 2 digits for the day, 3 letters for the month, 4 digits for the year. I tried to use the date format dd.MMM.yyyy , but that fails for 3 German months: 10.Mär.2016 10.Jun.2016 10.Jul.2016 That's because that's according to the docs, MMM actually stands for "date abbreviation", which does to guarantee or imply exactly three letters. How can I parse a date with exactly three letters for the month that will work in any language?

NSString to NSDate using NSDateFormatter returns null

混江龙づ霸主 提交于 2019-12-13 05:30:33
问题 dateFromString returns me null when I am trying to convert NSString to NSDate here is my code: NSString *dateString = @"Wed 16 Oct 2013"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[NSLocale systemLocale]]; [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; [dateFormatter setDateFormat:@"EEE dd MMM yyyy"]; [dateFormatter setFormatterBehavior:NSDateFormatterBehaviorDefault]; NSDate *myDate = [dateFormatter dateFromString: dateString]; Please

Convert a float into a time format mm:ss

跟風遠走 提交于 2019-12-13 05:09:38
问题 I'm searching a way with Objective-C to convert a float (audioPlayer.currentTime, which for example = 3.4592) into a time string with minutes and seconds (03:46) I tried this: static NSDateFormatter *date_formatter = nil; if (date_formatter == nil) { date_formatter = [[NSDateFormatter alloc] init]; [date_formatter setDateFormat:@"mm:ss"]; } NSDate *diff = [[NSDate alloc] initWithTimeIntervalSinceNow:audioPlayer.currentTime]; NSLog(@"%@", [date_formatter stringFromDate:diff]); ... but that's