nsdateformatter

Relative Date Formatting, output for past dates?

大憨熊 提交于 2019-12-07 03:11:06
问题 I am looking at using -[NSDateFormatter setDoesRelativeDateFormatting:] to present dates as "Today" or "Yesterday". I am only looking at dates in the past but am curious what options I would see localised for the UK. Just "Today" "Yesterday" or anything more convoluted like "The day before yesterday" Are the possible outputs listed anywhere so I can get an idea of the screen space needed to correctly display them? 回答1: Yes. They are listed in your console window when you run the following

change NSDate from one time zone to another [closed]

大城市里の小女人 提交于 2019-12-06 17:47:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Given a date in NSString like "2012-12-17 04:36:25" (which is GMT) how one can simply change it to other time zones like EST, CST All

Swift displaying the time or date based on timestamp

若如初见. 提交于 2019-12-06 16:43:39
I have an API that returns data including a timestamp for that record. In swift I have the timestamp element loaded and converted into a double and can then convert that into time. I want to be able to return the time if the date of the record is today and return the date if the record is not today. See below: let unixTimeString:Double = Double(rowData["Timestamp"] as! String)! let date = NSDate(timeIntervalSince1970: unixTimeString) // This is on EST time and has not yet been localised. var dateFormatter = NSDateFormatter() dateFormatter.timeStyle = .ShortStyle dateFormatter

Core Data sort tableview by formatted date

不羁的心 提交于 2019-12-06 16:05:04
I know how to sort Core Data objects in a tableview by NsDate, but this by default seems to create a new section for each object. I want to sort them by a medium formatted date with NSDateFormatter. How would I do this? For example, if I have 3 objects created on the same day, I want them to be in the same section with the section title being that Day, no time needed. Each object has an NSDate property. Thanks for your help. This is the code I have in fetchedResultsController with rgeorge's suggestions. What am I missing here? - (NSFetchedResultsController *)fetchedResultsController { if

objective-c: Conversion between TimeZones

ⅰ亾dé卋堺 提交于 2019-12-06 14:51:52
问题 I'm having problems converting a time string to a different timeZone. This is a string example as the one I retrieve from a server: @"5/14/2013 4:19am" I know the timeZone is America/New_York and I want to convert it to my local timeZone: Europe/Rome. Here is the code I wrote to test it: -(void) convertTimeZone { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.timeZone=[NSTimeZone timeZoneWithAbbreviation:@"GMT"]; dateFormatter.dateFormat=@"MM/dd/yyyy HH:mma";

NSDateFormatter not behaving properly when converting from Buddhist calendar to Gregorian calendar date formats

可紊 提交于 2019-12-06 14:35:09
问题 I'm making an app that supports conversion of dates from the Buddhist calendar to Gregorian (Note: The "General > International > Calendar" settings of the device I'm testing on is "Buddhist".). However, I can't figure out why the NSDateFormatter doesn't parse my dates properly. Here's my code: NSDate *now = [NSDate date]; NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter

Can I use NSDateFormatter to convert this date string to an NSDate?

走远了吗. 提交于 2019-12-06 13:16:48
I have this string... 2010-08-24T16:00:00-05:00 and I'd like to extract the time portion from it (i.e. 16:00) and convert it to its 12-hour equivalent (i.e. 04:00 pm). I'm trying to use NSDateFormatter to accomplish this, but it's not working... NSDateFormatter* dateformatter = [[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"hh:mm a"]; NSDate *date1 = [dateformatter dateFromString:[listOfTimes objectAtIndex:0]]; [dateformatter release]; Can I use NSDateFormatter with this date format? If not, how can I extract the time and convert it to its 12-hour time equivalent? Thanks!

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

Converting a String to a Date in Swift [duplicate]

与世无争的帅哥 提交于 2019-12-06 12:28:05
This question already has answers here : Date does not appear in UILabel (2 answers) Closed 2 years ago . I have date in string with format below code want to change in Date but i'm getting nil let addedDate = "Tue, 25 May 2010 12:53:58 +0000" let formatter = DateFormatter() formatter.dateFormat = "dd MM YYYY" let date1 = formatter.date(from: addedDate) print("DATE \(date1)") The date format needs to be for the string you are trying to convert, not the format you want back so formatter.dateFormat = "dd MM YYYY" should be formatter.dateFormat = "E, d MMM yyyy HH:mm:ss Z" You have to transform

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