nsdate

Sorting array based on date and time with two dictionary keys

谁说我不能喝 提交于 2019-12-06 12:51:32
问题 I am trying to sort an array based on date and time , I can successfully sort the array based on date both time is coming as another value in dictionary. So date comes as a string in format "yyyy-MM-dd" and time comes in as a string in format "HH:mm" Time value comes in key "starts" as string '"HH:mm"' format. I know somehow I need to combine two strings to 'yyyy-MM-dd HH:mm' but how? -(NSMutableArray *)sortArrayBasedOndate:(NSMutableArray *)arraytoSort { NSDateFormatter *formatter = [

Convert date from timezone to device local timezone and date

点点圈 提交于 2019-12-06 12:30:45
How can I convert date with timezone1 to date with device local timezone2? NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; [dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Jerusalem"]]; NSDate *date = [dateFormat dateFromString:timestamp]; then something like: [dateFormat2 setTimeZone:[NSTimeZone localTimeZone]]; date2 = [dateFormat2 dateFromDate:date withOtherTimeZone:zone]; UPDATE: I think I got it. //get source date from the server NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat

How to get the hours,minute and am/pm from a date? [duplicate]

岁酱吖の 提交于 2019-12-06 12:21:25
This question already has answers here : How to get the time in am/pm format iphone NSDateFormatter? (7 answers) Convert NSString to NSDate with new format (2 answers) Closed 6 years ago . I tried to extract hours,minute and am/pm from date but i am getting NULL output. I have shown below my code, please review it. NSString *dateStr=@"29/07/2013 02:00am"; NSDateFormatter * formatter=[[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mmaa"]; NSDate *date=[formatter dateFromString:dateStr]; NSString *finalDate=[formatter stringFromDate:date]; NSLog(@"%@",finalDate); Many thanks in

Remove milliSeconds from String in iOS

感情迁移 提交于 2019-12-06 11:08:08
Trying to remove milli seconds from String(date) NSString *dateString = @"2016-05-16 13:17:34.674194"; NSDateFormatter* formater = [[NSDateFormatter alloc] init]; [formater setDateFormat:@"dd/MM/yyyy HH:mm:ss"]; NSDate *date = [formater dateFromString:dateString]; NSLog(@"%@",[formater stringFromDate:date]); and i'm getting null i'm expecting o/p something like (with out milli seconds) "06/05/2016 13:17:34" Please suggest... Copy and paste this Code working Perfectly NSString *dateString = @" "; NSDateFormatter* dateFormatter1 = [[NSDateFormatter alloc] init]; dateFormatter1.dateFormat = @

How to determine if a business is open given the hours of operation (Swift-iOS)

不问归期 提交于 2019-12-06 10:02:58
问题 I have an app that I'm building in Swift that needs to determine if a store/restaurant is currently open. It queries a database that I have control of, so I can set the open hours however I'd like. Currently I have an openTime/closeTime column for each day of the week set as a timestamp. For example: MonOpen = 11:00, MonClose = 19:00. How can I use swift to determine if the place of business is currently open? I'm imagining something like if currentTime > MonOpen & currentTime < MonClose {...

Formatting Date to dd-MMM in iOS

爱⌒轻易说出口 提交于 2019-12-06 08:12:13
I've been searching this and couldn't quite find it. I have an object in a NSDictionary that contains a NSDate. Now standard NSDate objects are pretty long. and I want to show the user in dd-MMM format. For eg: The original date may be 2012-04-23 00:00:00 +0000 , for which I want the date to appear as 23 Apr I tried using NSDateComponents and NSDateFormatter but it didn't quite work. Probably I'm not figuring out the correct usage FOR the required format. Here's the code for better understanding: NSLog(@"From Dictionary, Date = %@",[tmpDict objectForKey:@"eventDate"]); NSDateFormatter

How to convert string date into NSDate with NSDateFormatter

隐身守侯 提交于 2019-12-06 07:48:12
I have the following date as NSString: Thu May 29 14:22:40 UTC 2014 I've tried to convert it to NSDate with the following code: NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"EEE MMM d HH:mm:ss zzz yyyy"; NSDate *utc = [fmt dateFromString:@"Thu May 29 14:22:40 UTC 2014"]; NSLog(@"UTC Date:%@:", utc); The result is nil I've tried several dateFormat regex expressions but with no luck. What am I missing here? Use NSDataDetector class a subclasss of NSRegularExpression, its takes a string that of a unknown date and converts it to NSDate object if it finds a match.

Determine NSDate for Memorial Day in a given year

♀尐吖头ヾ 提交于 2019-12-06 07:35:05
Is there a better way to determine the NSDate for Memorial Day (the last Monday in May) in a given year? NSInteger aGivenYear = 2013 ; NSCalendar* calendar = [NSCalendar currentCalendar] ; NSDateComponents* firstMondayInJuneComponents = [NSDateComponents new] ; firstMondayInJuneComponents.month = 6 ; // Thanks, Martin R., for pointing out that `weekOfMonth` is wrong for returning the first Monday in June. firstMondayInJuneComponents.weekOfMonth = 1 ; firstMondayInJuneComponents.weekday = 2 ; //Monday firstMondayInJuneComponents.year = aGivenYear ; NSDate* firstMondayInJune = [calendar

How to compare two date?

坚强是说给别人听的谎言 提交于 2019-12-06 07:34:36
I have three dates: (1) previousDate (2) currentDate (3) nextDate, I want to check whether currentDate is later then previous date and earlier than nextDate. How do I do that? iphonedev23 NSDateFormatter *df= [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *dt1 = [[NSDate alloc] init]; NSDate *dt2 = [[NSDate alloc] init]; dt1=[df dateFromString:@"2011-02-25"]; dt2=[df dateFromString:@"2011-03-25"]; NSComparisonResult result = [dt1 compare:dt2]; switch (result) { case NSOrderedAscending: NSLog(@"%@ is greater than %@", dt2, dt1); break; case NSOrderedDescending: NSLog(@

Is there a daylight savings check in Swift?

爷,独闯天下 提交于 2019-12-06 07:30:32
问题 I need to check to see if the current date is during daylight savings time. In pseudocode that would be like this: let date = NSDate() if date.isDaylightSavingsTime { print("Success") } I haven't been able to find the solution to this anywhere on the internet. 回答1: An NSDate alone represents an absolute point in time. To decide if a date is during daylight savings time or not it needs to be interpreted in the context of a time zone . Therefore you'll find that method in the NSTimeZone class