nsdateformatter

NSDate format issue

天涯浪子 提交于 2020-01-11 07:49:09
问题 Here is the code from the nsdate formatter... for some reason the value dateSelected is incorrect... instead of "April 30 2011 7:55PM" it returns 2011-05-01 02:55... any idea what am i doing wrong? NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setDateFormat:@"h:mm a"]; objEventInsert.eventtime = [outputFormatter stringFromDate:self.datePicker.date]; NSLog(@"%@",objEventInsert.eventtime); NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];

Swift: NSDateFormatter dateFromString returns nil on devices

我怕爱的太早我们不能终老 提交于 2020-01-11 02:20:07
问题 I found something that could solve my problem in Obj-c, but I'm not able to translate the code, so I'm asking for a Swift solution. I'm parsing some data from a JSON file and I get an issue retrieving the date; here is the code : println(data) // "Fri, 16 Jan 2015 11:49:00 +0100" var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "EEE, dd LLL yyyy HH:mm:ss ZZZ" let formattedDate = dateFormatter.dateFromString(data) println(formattedDate) // returns 'Optional(2015-01-16 11:49:00

NSDateFormatter time format depending on Locale

谁说我不能喝 提交于 2020-01-10 04:26:04
问题 I'm experiencing a really strange issue that sounds more like a system bug. I want to format a date using only Hour and Minute information and, if necessary, display AM/PM. Here is my code: extension NSDate { func localizedStringTime()->String { let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale.currentLocale() dateFormatter.dateFormat = "HH:mm" } } As you can see i'm using HH and not hh and as stated on Apple documentation it should automatically add AM/PM if user chooses

NSDateFormatter, am I doing something wrong or is this a bug?

北城以北 提交于 2020-01-09 02:15:08
问题 I'm trying to print out the date in a certain format: NSDate *today = [[NSDate alloc] init]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *dateStr = [dateFormatter stringFromDate:today]; If the iPhone is set to 24 hour time, this works fine, if on the other hand the user has set it to 24 hour time, then back to AM/PM (it works fine until you toggle this setting) then it appends the AM/PM on the end even though I

All dates between two Date objects (Swift)

情到浓时终转凉″ 提交于 2020-01-08 12:30:27
问题 I’m creating a date using NSDateComponents() . let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDateNSDate = calendar.dateFromComponents(startDate)! ... now I want to print all dates since the startDate until today, NSDate() . I’ve already tried playing with NSCalendarUnit , but it only outputs the whole difference, not the single dates between. let unit: NSCalendarUnit = [.Year, .Month, .Day,

All dates between two Date objects (Swift)

て烟熏妆下的殇ゞ 提交于 2020-01-08 12:30:20
问题 I’m creating a date using NSDateComponents() . let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDateNSDate = calendar.dateFromComponents(startDate)! ... now I want to print all dates since the startDate until today, NSDate() . I’ve already tried playing with NSCalendarUnit , but it only outputs the whole difference, not the single dates between. let unit: NSCalendarUnit = [.Year, .Month, .Day,

Need assistance regarding NSDateFormatter

怎甘沉沦 提交于 2020-01-07 09:28:55
问题 I only want date like "29-10-2014" with no time so i did this NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"dd-MM-yyyy"]; NSString *sDate = [df stringFromDate:date]; If I log the sDate I am getting perfect result. But I dont want NSString I want date object, to do that here what I did is NSDate *theDate = [df dateFromString:sDate]; Now I am getting 2014-10-29 19:00:00 +0000 I only want 29-10-2014 . 回答1: This is because -[NSDate description] returns you full

(Swift) Setting UIDatePicker View from User Input

微笑、不失礼 提交于 2020-01-07 03:01:30
问题 First I display a UIDatePicker on the screen and allow the user to choose a date and time. I save that value like this, which gets a date format that looks like this: 6/1/16, 1:47 PM let time = NSDateFormatter.localizedStringFromDate(datePicker.date, dateStyle: .ShortStyle, timeStyle: .ShortStyle) Later on in the application, I want users to be able to edit their original date, so when a button is pressed, I would like the UIDatePicker to display the time that they had originally chosen. I am

expected method to read dictionary element not found on object of type “NSDateFormatter*”

烈酒焚心 提交于 2020-01-07 02:35:08
问题 NSString *hashKey = [NSString stringWithFormat:@"%lu%lu%lu", (unsigned long)format.hash, (unsigned long)timeZone.hash, (unsigned long)locale.hash]; NSDateFormatter *formatters = [NSDate sharedDateFormatters]; NSDateFormatter *cachedDateFormatter = formatters[hashKey]; I am having trouble with this line: NSDateFormatter *cachedDateFormatter = formatters[hashKey]; Tells me: expected method to read dictionary element not found on object of type "NSDateFormatter*" Some context: +

Date formatter giving wrong date when converting to string Objective-C

时光总嘲笑我的痴心妄想 提交于 2020-01-06 14:04:43
问题 I'm converting a date to text to display in a text box and it converts fine. The 29,30 and 31 December 2013 gets converted to 2014 and 29,30 and 31 December 2014 gets converted to 2015. This is my code to convert the date to text NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MMM YYYY"]; self.pickupDateTextField.text = [dateFormatter stringFromDate:[self.datePicker date]]; NSLog(@"%@ %@",self.datePicker.date,self.pickupDateTextField.text);