nsdateformatter

How can I use NSDateFormatter to get the string “Yesterday”? [closed]

一曲冷凌霜 提交于 2019-12-23 07:38:18
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I want to format my NSDate so that a date that occurred yesterday will be displayed as "Yesterday'. Can this be done using NSDateFormatter ? 回答1: Use, [dateFormatter setDoesRelativeDateFormatting:YES] to indicate

Escape NSDateFormatter String

懵懂的女人 提交于 2019-12-23 07:15:12
问题 How to escape characters from NSDateFormatter format? NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; [dateFormater setDateFormat:@"dd/MM/yyyy \\a\\t HH:mm"]; NSString *dateFormated = [dateFormater stringFromDate:currentDate]; NSLog(@"%@", dateFormated); 回答1: You can escape text by enclosing it in single quotes: [dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"]; From the docs: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

Escape NSDateFormatter String

二次信任 提交于 2019-12-23 07:14:59
问题 How to escape characters from NSDateFormatter format? NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; [dateFormater setDateFormat:@"dd/MM/yyyy \\a\\t HH:mm"]; NSString *dateFormated = [dateFormater stringFromDate:currentDate]; NSLog(@"%@", dateFormated); 回答1: You can escape text by enclosing it in single quotes: [dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"]; From the docs: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

Problem formatting date using NSDateFormatter

我只是一个虾纸丫 提交于 2019-12-23 07:03:23
问题 I have the following date: 2011-09-09T18:01:47Z I want it to appear as "9/9/11 at 1:47PM" whatever the correct time is This code returns a null string: NSLog(@"TIME: %@",[message valueForKey:@"created_at"]); NSString* time = [message valueForKey:@"created_at"]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"]; NSDate* newTime = [dateFormatter dateFromString:time]; [dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];

Converting timestamp string with T and Z characters to NSDate [duplicate]

依然范特西╮ 提交于 2019-12-23 06:35:07
问题 This question already has answers here : Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate? (8 answers) Closed 5 years ago . I don't know how to convert this string to NSDate. Date is in this format "2012-10-21T07:00:00Z" I guess the problem is that I have no clue what those T and Z mean in the string :) NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]; NSDate *dateStart = [formatter dateFromString:@

Converting timestamp string with T and Z characters to NSDate [duplicate]

帅比萌擦擦* 提交于 2019-12-23 06:35:06
问题 This question already has answers here : Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate? (8 answers) Closed 5 years ago . I don't know how to convert this string to NSDate. Date is in this format "2012-10-21T07:00:00Z" I guess the problem is that I have no clue what those T and Z mean in the string :) NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]; NSDate *dateStart = [formatter dateFromString:@

NULL value from NSDateFormatter from XML

房东的猫 提交于 2019-12-23 05:23:17
问题 This was working fine before compiling with iOS4.0 and I can't figure out what's wrong. Here's the problem. I send my app scores from my database with a date/time on it. My goal is to store that in CoreData. When I use the code below I get a null value for the date. Code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"US"]; [dateFormatter setLocale:locale]; [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss ZZZ"

How to get yyyy-mm-dd hh:mm:ss format from 28 Jul 2011 22:33:57 in iPhone?

霸气de小男生 提交于 2019-12-23 04:16:51
问题 I have stuck in issue in which i have to convert date format is Thu, 28 Jul 2011 22:33:57 +0000 into yyyy-mm-dd hh:mm:ss please give me some idea how to do this? 回答1: What you want is to use the NSDateFormatter . Something like this: NSDateFormatter* f = [[[NSDateFormatter alloc] init] autorelease]; [f setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSString* dateString = [f stringFromDate:date]; Do note that the hours will still follow the users selected locale. Use kk:mm:ss to enforce a 24-hour time

NSDate formatter

随声附和 提交于 2019-12-22 11:14:11
问题 I try to convert a string to NSDATE with no luck unfortunately. Friday, October 22, 11:26:45 ET 2010 I know the options for formatting (http://sree.cc/objective-c/nsdate-format-string-in-objective-c) but i cant get it to work. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"???????"]; anyone? 回答1: Date Format Specifiers. So you'd probably need something like: [dateFormatter setDateFormat:@"eeee, MMMM dd, HH:mm:ss z yyyy"]; eeee - Local day of

GMT and UTC formatter with NSDateFormatter

让人想犯罪 __ 提交于 2019-12-22 10:32:14
问题 i wrote function that converting current time utc-gmt or gmt -utc. The functions just works fine if msgArrivedDate is null. If it's not ( that means , msgArrivedDate comes from rest service that doses not convert . jSON parse part : NSArray *messageSentTime = [[args valueForKey:@"messageSendDate"] objectAtIndex:0]; for(int i=0 ;i< [messageSentTime count]; i++) { //[self timeZoneFormatter:@"GMT" :[messageSentTime objectAtIndex:i]]; NSLog(@"Converted time = %@",[self timeZoneFormatter:@"GMT" :