nsdateformatter

Working out the start and end of a day. Swift

蓝咒 提交于 2019-12-08 06:04:01
问题 I have a function to work out the start and end of a week which works as expected. I want to implement another function which works out the start and end of a single day. I have the code below however I get the following error: Type of expression is ambiguous without more context. public class Date { let dateFormatter = NSDateFormatter() let date = NSDate() let calendar = NSCalendar.currentCalendar() func calcStartAndEndDateForWeek(durationOccurance: Double) { print("Calculating start and end

UIDatePicker giving wrong time [duplicate]

烈酒焚心 提交于 2019-12-08 04:30:35
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Getting date from [NSDate date] off by a few hours NSDate date don’t give me the right hour I have this piece of code: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm"]; NSString *formattedDateInString = [formatter stringFromDate:[self.datePicker date]]; NSLog(@"This is the formatted date (STRING) ---> %@" ,formattedDateInString); self.fromHourLabel.text =

Sharing an NSDateFormatter between NSTextFields in view-based NSTableView?

一世执手 提交于 2019-12-08 02:25:41
问题 I've searched high and low for the answer to this, but alas, I'm here. As I know that NSDateFormatter objects are costly to create, I don't want to instantiate one for every NSTextField inside of my table. The problem I'm facing is that my table is view-based (as opposed to cell-based), and when attempting to connect a shared instance of a date formatter, I get the yellow warning symbol and this message: Unsupported Configuration: Outlet 'formatter' of 'Text Field Cell - Table View Cell' is

Converting a String to a Date in Swift [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-08 01:57:27
问题 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)") 回答1: The date format needs to be for the string you are trying to convert, not the format you want back so formatter

How to get the hours,minute and am/pm from a date? [duplicate]

给你一囗甜甜゛ 提交于 2019-12-08 01:48:09
问题 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

How to convert string date into NSDate with NSDateFormatter

喜欢而已 提交于 2019-12-08 01:04:31
问题 I have the following date as NSString: Thu May 29 14:22:40 UTC 2014 I've tried to convert it to NSDate with the following code: NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"EEE MMM d HH:mm:ss zzz yyyy"; NSDate *utc = [fmt dateFromString:@"Thu May 29 14:22:40 UTC 2014"]; NSLog(@"UTC Date:%@:", utc); The result is nil I've tried several dateFormat regex expressions but with no luck. What am I missing here? 回答1: Use NSDataDetector class a subclasss of

iPhone UIDatePicker setMaximumDate

时光毁灭记忆、已成空白 提交于 2019-12-07 18:15:41
问题 I am trying to build a datepicker which has today as a minimum date and 1 Feb 2011 as Maximum date. I have set the minimum date as followed [picker setMinimumDate: [NSDate date]]; and this works just fine but the MaximumDate does not seem to be correct. [picker setMaximumDate: [NSDate dateWithNaturalLanguageString:@"11/02/01"]]; How do I set the maximum date correctly? 回答1: Found the answer. Thanks anyway for your help. [picker setDatePickerMode:UIDatePickerModeDate]; NSDateFormatter*

NSDateFormatter fails to return a datetime for UK region with 12 hour clock set [duplicate]

房东的猫 提交于 2019-12-07 14:57:10
问题 This question already has answers here : What is the best way to deal with the NSDateFormatter locale “feechur”? (4 answers) Closed 3 years ago . This code works for every region/locale combination I can determine EXCEPT if I set my phone to UK region with the 12 hour clock set. Can anyone tell me why? This works for every region including the UK with 12 hour clock set: NSDateFormatter *theDateFormatter = [[NSDateFormatter alloc] init]; theDateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss

Swift 3 changing date format

江枫思渺然 提交于 2019-12-07 12:37:20
问题 I want to get my Date in DD.MM.YYYY HH:mm:ss as a String. I use the following extension: extension Date { var localTime: String { return description(with: Locale.current) } } and the following code when my datePicker changes: @IBAction func datePickerChanged(_ sender: UIDatePicker) { dateLabel.text = datePicker.date.localTime let formatter = DateFormatter() formatter.dateFormat = "dd.MM.yyyy hh:mm" let TestDateTime = formatter.date(from: datePicker.date.localTime) } What am I doing wrong? 回答1

NSDate to RFC 2822 Date format

冷暖自知 提交于 2019-12-07 11:22:07
问题 Is there any efficient way to convert an NSDate to RFC 2822 Date format string ? I want to use this string to create an NSURLRequest and set the value of "If-Modified-Since" header field. 回答1: try to use an NSDateFormatter NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // maybe there exist a new-method now dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format NSString *dateString = [dateFormatter stringFromDate:myDate]; 回答2: Swift 3 let rfcDateFormat =