nsdateformatter

Convert gregorian date to Hijri date

≯℡__Kan透↙ 提交于 2019-12-10 11:41:19
问题 The source code comes from: Hijri (islamic) calendar in swift التاريخ الهجري How can I convert string date to NSDate? I just put them together but it has some mistake with the output. let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "YYYY-MM-DD" let GregorianDate = dateFormatter.dateFromString("\(Yeartext1.text!)-\(Monthtext1.text!)-\(Daytext1.text!)") let islamic = NSCalendar(identifier: NSIslamicCalendar) let components = islamic?.components(NSCalendarUnit(rawValue: UInt.max

Formatting Date to dd-MMM in iOS

泄露秘密 提交于 2019-12-10 11:13:36
问题 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

NSDateFormatter returns unexpected results

假如想象 提交于 2019-12-10 06:57:45
问题 Why does the following iOS 4.2 code return two different times? NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; [dateFormatter setTimeZone:gmt]; NSString* dateString = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"Date/Time is %@", dateString); NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease]; [inputFormatter

converting string to NSDate issue: [__NSDate Length] unrecognized selected

泪湿孤枕 提交于 2019-12-10 02:15:54
问题 indexNumber.row is a date like 2012-03-09 23:00:00 +0000 . I've tried a handful of different ways to get my date into an NSDate , but I keep getting the title error. NSString *inputString = [self.measurements objectAtIndex:indexNumber.row]; // Convert string to date object NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *date = [dateFormatter dateFromString:inputString ]; NSLog(@"date format is: %@", date); Any ideas why I

Using NSDateFormatter on the iPhone, protect locale but lose date components

独自空忆成欢 提交于 2019-12-10 01:21:02
问题 This is a slightly tricky question. I am using NSDateFormatter on the iPhone but I wanted to only show a standard date without the years component. But retain the users locale formatting for their date. I could easily override the formatting using [dateFormatter setDateFormat:@"h:mma EEEE MMMM d"]; // hurl.ws/43p9 (date formatting) But now the date is in my in en-nz format eg 12:01PM Wednesday July 7. So I have totally killed the locale for any other users around the world. I would like to

Unable to Parse Date using NSDateFormatter

落花浮王杯 提交于 2019-12-09 12:58:08
问题 I am fetching a RSS, in which i receive the following Date stamp: 2010-05-10T06:11:14.000Z Now i am using NSDateFormatter to parse this datetime stamp. [parseFormatter setDateFormat:@"yyyy-MM-dTH:m:s.z"]; But its not working fine if just remove the time stamp part it works for the date [parseFormatter setDateFormat:@"yyyy-MM-d"]; But if i add the rest of the stuff it returns nil. Any idea ? Thanks in Advance.... 回答1: You need to parse zero padded values for d, H, m, s You need to escape the

Hours in NSDate every time in 24-hour style?

社会主义新天地 提交于 2019-12-09 04:39:29
问题 I have this date formatter: NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; [timeFormatter setDateFormat:@"HH:mm"]; If I use this: NSDate *myDate = [timeFormatter dateFromString:@"13:00"]; It returns this: "1:00" This is because the simulator has switched off 24-hour. But for my app I really need "13:00" instead of "1:00" --- EDIT 1 --- Added new code: NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendarUnit unitFlags =

How to properly convert the Last-Modified header from an HTTP response to an NSDate on iOS

若如初见. 提交于 2019-12-09 04:38:48
问题 I am looking for a fully working solution, one that works with: any iOS locale or timezone any/most HTTP servers Xcode 4.0.2 (see why) Current broken code: NSString lastModifiedString = @"Mon, 06 Jun 2011 12:47:05 GMT"; NSDateFormatter *df = [[NSDateFormatter alloc] init]; //df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"; df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; df.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; df.timeZone = [NSTimeZone

Nsdateformatter returns me day in language of the phone selected. Can it return me only English all the time?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 04:18:12
问题 I am using dateformatter to get days and time in the my application. But I am facing an issue when I change the language of the phone dateformatter returns me day and time of the selected language of the phone due to which my app crashes as we are not supporting multiple languages. Please find the below code snippet: NSDate *date=[NSDate date]; NSDateFormatter *objTimeFotmatter=[[NSDateFormatter alloc]init]; [objTimeFotmatter setDateFormat:@"HH:mm"]; NSDateFormatter *objDayFotmatter=[

How to convert MySQL datetime to NSDate?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 03:22:00
问题 MySQL returns this datetime: 2014-05-07T16:58:44.000Z How, with what datetime format I can create NSDate ? I far as I found this, but it does not work: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; NSDate *date = [df dateFromString: valueStr]; 回答1: Your format string is close, but you want to specify the milliseconds with SSS , too: [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSX"]; Also, the Z in your date string stands for "Zulu