nsdateformatter

How to Convert MYSQL DateTime to NSDate - Swift [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-13 09:59:59
问题 This question already has an answer here : How to convert MySQL datetime to NSDate? (1 answer) Closed 4 years ago . "2015-06-30T17:30:36.000Z" is an example of DateTime value in MySQL. How to convert it to NSDate in Swift? Below is my code but it does not work var sqlDateFormatter = NSDateFormatter() sqlDateFormatter.dateFormat = "yyyy’-‘MM’-'dd’T'HH’:'mm’:'ss'Z’" self.whenPublished = self.sqlDateFormatter.dateFromString("2015-06-30T17:30:36.000Z") 回答1: You just need to add the milliseconds

nil on conversion string to date [duplicate]

半世苍凉 提交于 2019-12-13 09:55:15
问题 This question already has answers here : Converting NSString to NSDate (and back again) (17 answers) Closed 3 years ago . I try to convert string to date my method looks like this func createDateFromString(string: String) -> NSDate { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format let date = dateFormatter.dateFromString(string) return date! } But I have a runtime a error. fatal error: unexpectedly found nil while

date not showing in correct manner

主宰稳场 提交于 2019-12-13 09:49:52
问题 I have some 7 UILabels which will show the date like below: Jan,2016 (label) (button) < **29Dec 30Dec 31Dec 1Jan 2Jan 3Jan 4Jan** >(Button) Also I am having two arrow UIButton at both side when user can move to back date or previous date. And i have one lable to show the current month based on my date showing Here is my full code: Viewcontroller.h @property (weak, nonatomic) IBOutlet UILabel *flabel; @property (weak, nonatomic) IBOutlet UILabel *slabel; @property (weak, nonatomic) IBOutlet

Converting can NSString to NSDate format in objective C [duplicate]

泪湿孤枕 提交于 2019-12-13 09:46:19
问题 This question already has answers here : Convert string to date in my iPhone app (4 answers) issue with date formatting using NSDateFormatter (3 answers) Closed 6 years ago . How can i convert the following string "October 24,Monday 12:30 AM EST" to NSDateFormat. i tried this code NSDateFormatter *dateformat=[[NSDateFormatter alloc]init]; [dateformat setDateFormat:@"MM/DD/YYYY hh:mm a"]; NSDate *datefor=[dateformat dateFromString:appDelegate.appoinmentString]; [dateformat setDateFormat:@"MM

How to compare two time from NSDate. Returning nil for nsdate when doing comparision. #debug my code

回眸只為那壹抹淺笑 提交于 2019-12-13 09:26:02
问题 Here is the code: // get current date/time NSDate *today = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; [dateFormatter setDateFormat:@"HH:mm:ss"]; NSString *currentTime = [dateFormatter stringFromDate:today]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@"AM" withString:@""]; currentTime = [currentTime

I didn't get correct time when using time formatter

我只是一个虾纸丫 提交于 2019-12-13 09:05:23
问题 When i tried to get date and time from two textfields, i got incorrect time. my input date.text = may 20 2000 time.text = 02:00 AM but i got the time in nslog is :00:00:00 NSString *datestring = self.date.text; NSString *timestring = self.time.text; NSString *combined = [NSString stringWithFormat:@"%@ %@", datestring, timestring]; NSLog(@"%@",combined); NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MMMM dd yyyy HH:mm:ss"]; NSDate *dates =

Issues with initWithFormat value from server

送分小仙女□ 提交于 2019-12-13 09:04:33
问题 Please how do I make my initWithFormat to display in as 8:00am - 2:30pm? Help please!! I have already added "dd-MM-yyyy 'at' h:mm:ss a" //opening NSString *startDate= ((Timeslot *)[self.timeslots objectAtIndex:i]).startDateTime; NSArray *split =[startDate componentsSeparatedByString: @"T"]; NSString* clock =[split objectAtIndex: 1]; NSArray *aux= [clock componentsSeparatedByString:@":"]; NSString *startTime = [[NSString alloc] initWithFormat:@"%@:%@",[aux objectAtIndex:0],[aux objectAtIndex:1

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

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