nsdate

NSString to NSDate for yyyy-MM-dd'T'HH:mm:ss.SSS+05:30 format

孤街浪徒 提交于 2019-11-30 17:42:50
My date string that I am getting is 2014-01-08T21:21:22.737+05:30 of this format. How do i confer it to NSDate? I tried: NSString *currentDateString = @"2014-01-08T21:21:22.737+05:30"; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS+05:30"]; NSDate *currentDate = [dateFormatter dateFromString:currentDateString]; NSLog(@"CurrentDate:%@", currentDate); It returns nil. Any thoughts? Use this code it is working fine your dateFormatter was wrong . NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init]; NSString *currentDateString = @"2014-01-08T21:21:22.737+05:30"; [dateFormatter

Parsing a RFC 822 date with NSDateFormatter

家住魔仙堡 提交于 2019-11-30 17:23:52
I'm using a NSDateFormatter to parse a RFC 822 date on the iPhone. However, there is no way to specify optional elements in the date format. There are a couple of optional parts in the RFC 822 specification which is breaking the date parser. If nothing works out, I'd probably have to write a custom parser to obey the specs. For example, the day name is optional in the spec. So both these dates are valid: Tue, 01 Dec 2009 08:48:25 +0000 is parsed with the format EEE, dd MMM yyyy HH:mm:ss z 01 Dec 2009 08:48:25 +0000 is parsed with the format dd MMM yyyy HH:mm:ss z This is what I am currently

Parsing a RFC 822 date with NSDateFormatter

我只是一个虾纸丫 提交于 2019-11-30 16:38:09
问题 I'm using a NSDateFormatter to parse a RFC 822 date on the iPhone. However, there is no way to specify optional elements in the date format. There are a couple of optional parts in the RFC 822 specification which is breaking the date parser. If nothing works out, I'd probably have to write a custom parser to obey the specs. For example, the day name is optional in the spec. So both these dates are valid: Tue, 01 Dec 2009 08:48:25 +0000 is parsed with the format EEE, dd MMM yyyy HH:mm:ss z 01

NSPredicate- For finding events that occur between a certain date range

本小妞迷上赌 提交于 2019-11-30 16:09:36
This is a little more complicated then just NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate >= %@ AND endDate <= %@", startDay,endDay]; I'm building a calendar app and I need to pull events out of my core data store that occur on a given day. However, it's possible for an event to start/end on a different day then the day I'm trying to display, e.g. My Date Range (Start = 2011-12-02 00:00:00 to End = 2011-12-02 23:59:59) An Event (Start = 2011-12-01 23:00:00 to End = 2011-12-02 05:00:00) How can I write a predicate to determine if that event falls in that date range. Keep

NSDate dateFromString deprecated?

社会主义新天地 提交于 2019-11-30 15:51:56
I'm trying to use the NSDate dateFromString method but I'm getting an warning and it's crashing the app. The code looks like: NSString *pickerDate = [NSString stringWithFormat:@"%@", timeSelector.date]; NSDate *defaultDate = [NSDate dateFromString:pickerDate]; The warning is: 'NSDate' may not respond to '+dateFromString'. It appears that method is deprecated (in the midst of an upgrade from XCode 2 to 3. What alternate method can I use to create a date from a string? NSDateFormatter is the intended way for you to get an NSDate from an NSString . The most basic usage is something like this:

how to convert datetime format in NSString?

旧时模样 提交于 2019-11-30 15:42:46
I have got value from the xml 2009-11-23T05:24:41.000Z . Now i want to display string like this: Wed, Nov 4, 2009 8:00 PM - Wed, Nov 4, 2009 9:00 PM How it possible? You'll want to do something like this: NSDateFormatter * inputFormatter = [ [ [ NSDateFormatter alloc ] init ] autorelease ]; NSDateFormatter * outputFormatter = [ [ [ NSDateFormatter alloc ] init ] autorelease ]; [ inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'.000Z'" ]; [ outputFormatter setDateFormat:@"EEE, MMM d, yyyy h:mm a" ]; NSString * inputString = @"2009-11-23T05:24:41.000Z"; NSDate * inputDate = [ inputFormatter

NSDateFormatter- stringFromDate not returning AM/PM

依然范特西╮ 提交于 2019-11-30 14:57:09
问题 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mm:ss a"]; NSLog(@"Today's Time: %@", [formatter stringFromDate:[NSDate date]]); The above code just gives the following output Today's Time: 15:46:43 I want the output to be Today's Time: 3:46 PM . I surfed a lot and i did not find a way to show AM/PM. Would be really helpful if someone can help me find a way out. I am using XCode 6.3 and my Device has iOS 8.3 installed in it. 回答1: Check your device

Converting a Gregorian date to Julian Day Count in Objective C

那年仲夏 提交于 2019-11-30 14:13:29
I need Objective C method for converting Gregorian date to Julian days same as this PHP method (GregorianToJD). According to http://en.wikipedia.org/wiki/Julian_day , the Julian day number for January 1, 2000, was 2,451,545. So you can compute the number of days between your date and this reference date. For example (Jan 1, 2014): NSUInteger julianDayFor01012000 = 2451545; NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSDateComponents *comp = [[NSDateComponents alloc] init]; comp.year = 2014;

SWIFT: How do I add hours to NSDate object

核能气质少年 提交于 2019-11-30 14:01:45
I generate a NSDate object from string. let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT") let stringToDate = dateFormatter.dateFromString(dateFromService) // 2015-07-20 12:00:43 +0000 I get this string value from webserver. I need to modify for personal device timezone. Want to add hours this stringToDate object but not work var addHours : Int = 2 // 2 hours will be added var newDate = stringToDate.dateByAddingTimeInterval(addHours) Duncan C You're asking the wrong question. This is what's known as an

NSDateFormatter- stringFromDate not returning AM/PM

天大地大妈咪最大 提交于 2019-11-30 13:28:45
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mm:ss a"]; NSLog(@"Today's Time: %@", [formatter stringFromDate:[NSDate date]]); The above code just gives the following output Today's Time: 15:46:43 I want the output to be Today's Time: 3:46 PM . I surfed a lot and i did not find a way to show AM/PM. Would be really helpful if someone can help me find a way out. I am using XCode 6.3 and my Device has iOS 8.3 installed in it. Check your device settings for 24 hour time. If it is on, turn it off. Your code is perfectly fine. I am getting output as shown