nsdateformatter

Issue with NSDate from NSDateComponents

怎甘沉沦 提交于 2019-12-14 03:28:56
问题 i have a string like 2013-03-05T07:37:26.853 and i want to get the Output : 2013-03-05 07:37:26 . I want the final output in NSDate object. i am using below function to convert desire output. and it returning wrong time. - (NSDate *) getDateFromCustomString:(NSString *) dateStr { NSArray *dateStrParts = [dateStr componentsSeparatedByString:@"T"]; NSString *datePart = [dateStrParts objectAtIndex:0]; NSString *timePart = [dateStrParts objectAtIndex:1]; NSArray *dateParts = [datePart

a date string without year to NSDate with year

删除回忆录丶 提交于 2019-12-14 03:09:57
问题 I have a date string of "5:09 pm Wed Sep 2",which is coming from server. when converting the string into NSDate . "2000-09-02 17:09:00 +0000" but the year should have been "2015" like: "2015-09-02 17:09:00 +0000" Here is my code please let me know where is the problem NSString *dateStr = @"5:09 pm Wed Sep 2"; // Convert string to date object NSString *dateFormat= ([self hasAMPM])?@"hh:mm a EEEE MMM d":@"hh:mm a EEEE MMM d" ; NSDate * date = [self toLocalTime:[self convertDateFromString

NSDateFormatter for this format

╄→尐↘猪︶ㄣ 提交于 2019-12-13 22:29:10
问题 I want to make an NSDateFormatter object for this date format (for example): 2016-04-15 15:00:00 I've tried yyyy-mm-dd hh:mm:ss but then when I am trying to attach it to a date like that: date = [formatter dateFromString:dateString]; It gives me nil . what is the correct way to do it? Thank you! 回答1: set date format as 2016-04-15 15:00:00 yyyy-MM-dd HH:mm:ss your date string is 24 hour format 回答2: Here's all you need for date formatting: https://developer.apple.com/library/ios/documentation

action listener for timePicker

大憨熊 提交于 2019-12-13 20:17:33
问题 I have a timePicker which I have declared a listener if user change the time string sets on textFiled. func timeFromAction(){ DispatchQueue.main.async { self.timePickerFrom.datePickerMode = UIDatePickerMode.time //self.timePickerFrom.minimumDate = self.minDate print(self.minDate) self.timePickerFrom.date = self.minDate // current date I have achieve from millisecond to date self.timePickerFrom.locale = Locale(identifier: "fa_IR") self.timePickerFrom.calendar = Calendar(identifier: Calendar

NSDateFormatter return nil in iOS 5

不想你离开。 提交于 2019-12-13 19:16:54
问题 With iOS 6 everything is ok but with iOS 5 myDate return nil NSString *dateString = @"2012-07-12T11:00:00+02:00"; NSLocale *deLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZZ"]; dateFormatter.locale = deLocale; NSDate *myDate = [dateFormatter dateFromString:dateString]; It must be a Problem with the DateFormat i believe 回答1: NSDate *today = [NSDate

iOS RestKit Date parsing

ぐ巨炮叔叔 提交于 2019-12-13 13:29:25
问题 In an old iOS project I had to parse dates that come in the format dd/MM/yyyy so I put these lines in a static method of my AppDelegate and it worked as expected // Set the Dateformatter for the Dates returned by Knowledge tt/mm/yyyy NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd/MM/yyyy"]; [[RKValueTransformer defaultValueTransformer] insertValueTransformer:dateFormatter atIndex:0]; However in the actual projects my dates come in a slightly

Where to look up the date format specifiers used in cocoa / cocoa touch?

青春壹個敷衍的年華 提交于 2019-12-13 11:38:45
问题 For example: [dateFormatter setDateFormat:@"yyyy-MM-DD HH:mm:ss"]; I guess there's a list somewhere that shows all those date format specifiers, but can't find any. The NSDateFormatter docs seem to not mention these. 回答1: It uses Unicode Technical Standard #35. Also note: NSDateFormatter changes a lot with iOS 4, so make sure you read the documentation carefully. 来源: https://stackoverflow.com/questions/3076370/where-to-look-up-the-date-format-specifiers-used-in-cocoa-cocoa-touch

NSCalendar date error

為{幸葍}努か 提交于 2019-12-13 11:35:16
问题 I'm trying to use NSCalendar with NSIslamicCalendar identifier. But the day result is not good, her's my code: NSCalendar *calandar = [[NSCalendar alloc]initWithCalendarIdentifier:NSIslamicCalendar]; NSDateComponents *components = [calandar components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]]; NSInteger theDay = [components day]; NSInteger theMonth = [components month]; NSInteger theYear = [components year]; [components setDay:theDay]; [components

DatePicker is not returning the correct date. Is it because NSDate defaults to absolute time?

♀尐吖头ヾ 提交于 2019-12-13 10:19:02
问题 I saved a task's due date as 8:45 today. However the log shows the due date as 2013-04-26 01:45:46 +0000 What gives? Here's my code #import "DatePickerViewController.h" #import <Parse/Parse.h> #import "ListItemObject.h" @class ListItemObject; @interface DatePickerViewController () @end @implementation DatePickerViewController @synthesize dateLabel; @synthesize pick; @synthesize listFieldText; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super

How to format the date using NSDateFormatter in Swift for iOS?

二次信任 提交于 2019-12-13 10:14:08
问题 I am trying to parse this date "18th of June 2016. Saturday" to "18/06/2016" I'm aware this can be done using the regex method but I'm not sure how you'd get an output using that. A method using NSDateFormatter in swift would be preferred 回答1: Here you go. NSDateFormatter does not support days with ordinal indicators, so you have to get rid of them. You can use regex: let regex = try NSRegularExpression(pattern: "[st|nd|rd|th]", options: NSRegularExpressionOptions()) regex