nsdateformatter

Date Format problem - convert string to date in MMM d, yyyy format

醉酒当歌 提交于 2019-12-11 16:54:48
问题 HI, i have a string 2011-05-13T00:00:00 and i want to convert this string in MMM d, yyyy format. any Help? 回答1: Read this: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1 I'm not at my Mac, but this should give you a head-start: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'"]; NSDate *originalDate =

How to parse these time zones with NSDateFormatter?

可紊 提交于 2019-12-11 15:04:34
问题 I'm parsing a large number of internet dates. First I try a formatter with en_US_POSIX locale, then with en_GB . The code looks more or less like this: { NSDate *date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_US_POSIX"]; if (date) return date; date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_GB"]; return date; } - (NSDate*) dateWithDateFormat:(NSString*)dateFormat localeIdentifier:(NSString*

NSDateFormatter not Working for Twitter date

隐身守侯 提交于 2019-12-11 12:57:21
问题 I am trying to format a date i am getting from twitter using the STTwitter library. However the code that I've tried so far has not worked. Code for getting the date from twitter: NSString *dateString = [status valueForKey:@"created_at"]; This returns the time, date, time zone and year in which the tweet was made which looks messy. I tried using the following code to convert this and make it neater: NSDateFormatter *dateFormatter =[[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@

iOS DateFormatter giving nil ,When device Timezone and region changes [duplicate]

久未见 提交于 2019-12-11 12:04:21
问题 This question already has answers here : What is the best way to deal with the NSDateFormatter locale “feechur”? (4 answers) DateFormatter doesn't return date for “HH:mm:ss” (1 answer) Swift: NSDateFormatter dateFromString returns nil on devices (1 answer) Closed last year . I have a date in string like this let time = "Wed Oct 10 12:22:32 UTC 2018" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "EE MM dd HH:mm:ss zz yyyy" let rawDate = dateFormatter.date(from: time) //

How to get date in “yyyy-MM-dd'T'HH:mm:ss.SSSZ” format?

我是研究僧i 提交于 2019-12-11 09:45:04
问题 i have date in this format 2014-09-20 04:45:20 +0000 and i need to convert this to yyyy-MM-dd'T'HH:mm:ss.SSSZ format.I tried with the following code NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]; NSDate *date = [formatter dateFromString:@"2014-09-20 04:45:20 +0000"]; NSLog(@"%@",date); but date giving me null value.. I am geting 2014-09-20 04:45:20 +0000 from time picker so anythg needs to be done on picker side will

Check if a date is between two days in iPhone

馋奶兔 提交于 2019-12-11 07:41:41
问题 I know how to compare dates.In my case, let Date1 = 2011-10-14 & Date2 =2011-10-20 .And I want to check if 15th Oct lie between Date1 and Date2.I'm using following codes for this: if ( [date compare:Date1] == NSOrderedDescending && [date compare:Date2] == NSOrderedAscending) { //write codes } But this will not check if 15th oct lie between 14th and 20th Oct.rather it check for whole date. So, How will I implement this. Thnx in advance. 回答1: I hope the following code would help you. Assuming

NSDateFormatter gives different output/wrong (GMT?) time

和自甴很熟 提交于 2019-12-11 07:39:59
问题 I have tried setting the timezone and locale of the NSDateFormatter but I can't seem to get anything to work. Here is the code NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"]; NSString *myFireDateString=[@"9/17/11" stringByAppendingString:@" 09:00:00"]; NSDate *myFireDate = [dateFormat dateFromString:myFireDateString]; NSLog(@"The datestring is is %@",myFireDateString); NSLog(@"The formatted date is %@",myFireDate); Here is the

Why date formatter crashes?

☆樱花仙子☆ 提交于 2019-12-11 06:08:33
问题 My below code is working fine. I don't know why it crashes sometimes(Mostly on application launch. 1 case out of ~100). extension Formatter { static let enUSPOSIX: DateFormatter = { let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX")// return formatter }() } let dateFormatter = Formatter.enUSPOSIX dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss+hh:mm" let date = dateFormatter.date(from: "2018-05-13T00:00:00+05:30") dateFormatter.timeZone = TimeZone

iOS NSDateFormatter Timezone

蹲街弑〆低调 提交于 2019-12-11 05:59:22
问题 I have some code that takes a string, turns it into a date, reformats it then spits it out as another string: [formatter setDateFormat:@"YYYY'-'MM'-'DD','HH:mm:ss','ZZZ"]; [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]]; NSDate *date = [formatter dateFromString:combinedString]; [formatter setDateStyle:NSDateFormatterLongStyle]; NSString *finishedString = [formatter stringFromDate:date]; Basically, it works fine except for the timezones. All of the input strings are

Cannot find the right date format (NSDateFormatter) for this

本小妞迷上赌 提交于 2019-12-11 05:57:19
问题 I cannot convert this kind of strings to NSDate, please help me out here. What am I doing wrong below? dateString = @"201302051614461"; NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"YYYYMMddHHmmSSSSS"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"dateString: %@", dateString); NSLog(@"date: %@", date); This returns with an empty date. 回答1: If I break it like this 2013 02 05 16 14 46 1 Then the format string is @"yyyyMMddHHmmssS 回答2