nsdateformatter

comparing time without date swift3

与世无争的帅哥 提交于 2019-12-25 14:39:09
问题 I am using an API to get a list of times which is five times a day as string in (AM,PM) format without date, ("4:30 AM","1:00 PM","3:20: PM","6:40 PM","9:10 PM") what I am trying to do is to show the next time in the screen depends on the current time on the iPhone so if the time now is 5:00 PM the time should display on the screen is 6:40 PM how can I compare times in swift without including the dates because I tried to convert the list of times I have to Date type but unfortunately am

Swift date formatting, getting the date back from server is not the same as sent to the server

纵然是瞬间 提交于 2019-12-25 09:14:37
问题 I am trying to parse a date that is sent to the server. Now the date that is recieved from the server is "2016-05-10T22:34:00.000Z" And here is my code to get a formatted date out of the above date string : let format="yyyy-MM-dd'T'HH:mm:ss.SSSZ" let dateFmt = NSDateFormatter() dateFmt.dateFormat = format let newreadableDate = dateFmt.dateFromString(dateString) print(newreadableDate!) dateFmt.dateFormat = "MMM dd hh:mm a" print("Formatted date is : \(dateFmt.stringFromDate(newreadableDate!))"

objective-c - NSDateFormatter returns wrong date

只愿长相守 提交于 2019-12-25 07:59:06
问题 I have this piece of code: // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MMMM d, YYYY"]; NSDate *formatDate = [dateFormat dateFromString:self.date]; NSLog(@"1-%@", self.date); NSLog(@"2-%@", formatDate); NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:formatDate]; NSString *dateCal = [NSString stringWithFormat:@"%d/%d/%d",

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

How can I print a day of the week in a locale-friendly way using NSDateFormatter?

陌路散爱 提交于 2019-12-25 06:26:50
问题 I noticed NSDateFormatter allows for an enum called .FullStyle that will print Tuesday, April 12, 1952 AD . But how do I just print Tuesday in a locale-safe way? 回答1: You need to use NSDateFormatter dateFormat = "cccc" . If you need a reference for date format patterns you can take a look at this link: extension NSDate { struct Formatter { static let dayOfWeek: NSDateFormatter = { let formatter = NSDateFormatter() formatter.dateFormat = "cccc" // Stand Alone local day of week return formatter

Date Formatter issue in ObjC [duplicate]

为君一笑 提交于 2019-12-25 03:02:02
问题 This question already has answers here : What format string do I use for milliseconds in date strings on iPhone? (4 answers) Closed 4 years ago . I need to convert a date string "2015-03-10 00:00:00.000"(string from web service) to NSDate. I have used code like this NSDateFormatter *fromDateFormat = [[NSDateFormatter alloc] init]; [fromDateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *outputDate = [fromDateFormat dateFromString:@"2015-03-10 00:00:00.000"]; outputDate is nil. I tried

How to sort the Array that contains date in strings in ascending order

霸气de小男生 提交于 2019-12-25 01:56:00
问题 I have array of dictionaries ,In every dictionary contains one date parameter . The array of date parameters(contains in dictionaries) as follow: [@"16-1-2015 7:00PM",@"15-1-2014 11:30AM",@"14-1-2014 7:00PM", @"15-1-2015 6:30AM ".@"16-1-2015 8:30PM"] I need output like : [@"16-1-2015 8:30PM",@"16-1-2015 7:00PM",@"15-1-2015 6:30AM ", @"15-1-2014 11:30AM",@"14-1-2014 7:00PM"]; 回答1: You could try this: NSArray *dateStringArray = @[ @"16-1-2015 7:00PM", @"15-1-2014 11:30AM", @"14-1-2014 7:00PM",

NSDateFormatter dateFromString for 24hr date gives wrong time

我只是一个虾纸丫 提交于 2019-12-24 23:40:26
问题 I want to add event to native calender.I am having problem in getting date accurate time from string. I have set locale,24 hr format. but still getting the same bug. EKEvent *event = [EKEvent eventWithEventStore:self.eventStore]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *locale =[[[NSLocalealloc]initWithLocaleIdentifier:@"en_US_POSIX"]autorelease]; [dateFormatter setLocale:locale]; [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"]; event.startDate=

How to get the day of week from a given number

我们两清 提交于 2019-12-24 18:05:11
问题 I want to have the day of week name for a given number, here is the pseudo-code : getDayStringForInt:0 = sunday getDayStringForInt:1 = monday getDayStringForInt:2 = tuesday getDayStringForInt:3 = wenesday getDayStringForInt:4 = thursday getDayStringForInt:5 = friday getDayStringForInt:6 = saturday I have tried with the follow code, but some thing is not working ... - (void) setPeriodicityDayOfWeek:(NSNumber *)dayOfWeek{ gregorian = [[NSCalendar alloc] initWithCalendarIdentifier

Convert between date formats in Objective-C

一笑奈何 提交于 2019-12-24 16:31:10
问题 I am trying to convert a date into a different format. I'm receiving my date as an NSString with the following format: EEE MMM dd HH:mm:ss ZZZ yyyy , and am attempting to change it to this format: dd-mm-yy . However, I am not able to get it in desired format. This is my current code: NSString *dateStr = [NSString stringWithFormat:@"%@",[dict valueForKey:@"createdOn"]]; [dateFormatter setDateFormat:@"EEE MMM dd HH:mm:ss zzz yyyy"]; NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"IST"]