nsdateformatter

IOS 6 NSDateFormatter

佐手、 提交于 2019-12-17 16:52:45
问题 Please help me with the dateformatter on IOS6, please see the code below NSString stringDate = @"12/31/9999"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"MM/dd/yyyy"]; NSDate *dateCheck = [dateFormatter dateFromString:stringDate]; NSLog(@"Date = %@", dateCheck); Output is Date = 1999-12-31 08:00:00 +0000 This was the output when converting the string date to date 12/31/9999. From the previous version of IOS6 the output is Date = 9999-12-31 08

Using DateFormatter on a Unix timestamp

与世无争的帅哥 提交于 2019-12-17 15:48:10
问题 I get a crash when running and it points at the dateFormmater.timezone . The error in the console is: Could not cast value of type 'Swift.Optional' (0x1192bf4a8) to 'NSTimeZone' (0x1192c0270). the value of rowEvents.date is "1480134638.0" Im trying to pull out a Unix timestamp from Firebase saved as a string. Convert it to Date and again save it as a string so I can post it on a cell label. I got this code from StackOverflow. I plugged in my data and everything is all good until I run it. I

Convert NSDate to String in iOS Swift [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-17 10:47:48
问题 This question already has answers here : Convert NSDate to NSString (14 answers) Closed last year . I am trying to convert a NSDate to a String and then Change Format. But when I pass NSDate to String it is producing whitespace. let formatter = DateFormatter() let myString = (String(describing: date)) formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let yourDate: Date? = formatter.date(from: myString) formatter.dateFormat = "dd-MMM-yyyy" print(yourDate) 回答1: you get the detail information from

1st april dates of 80s failed to parse in iOS 10.0

故事扮演 提交于 2019-12-17 04:07:12
问题 I found that DateFormatter date(from:) method can't parse a couple of specific dates. Method returns nil for the 1st april of 1981-1984 years. Is it a bug of Foundation? What can we do to perform parsing of such dates? Xcode 8.0, iOS SDK 10.0. Here is a screenshot of a short playground example: 回答1: This problem occurs if daylight saving time starts exactly on midnight , as it was the case in Moscow in the years 1981–1984 (see for example Clock Changes in Moscow, Russia (Moskva)). This was

DateFormatter's method date(from: String) returns nil for specific dates in specific languages in Swift

跟風遠走 提交于 2019-12-17 03:42:40
问题 I really don't get what is happening with this code, I'm trying to convert a string to date. What I don't understand is that the conversion works for most of the dates, but doesn't work specially for only 2 dates. let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale(localeIdentifier: "es") dateFormatter.dateFormat = "dd 'de' MMMM" dateFormatter.dateFromString("1 de octubre") dateFormatter.dateFromString("2 de octubre") dateFormatter.dateFromString("3 de octubre")

swift NSDateFormatter not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 03:20:42
问题 I'm trying to format time as follows: let formatter = NSDateFormatter() formatter.dateFormat = "hh_mm_ss" let d = formatter.stringFromDate(NSDate()) println("formatted text is: \(d)") Suppose that current time is Sep 3, 2014 22:15:30 When I run this script on playground, it prints the time correctly formatted: 22_15_30 . When running this on AppDelegate, it doesn't print the time formatted: 22:15:30 I'm using xcode 6 beta 5... Am I missing something? Why stringFromDate doesn't return the

Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

寵の児 提交于 2019-12-17 02:26:26
问题 I basically need to get current date and time separately, formatted as: 2009-04-26 11:06:54 The code below, from another question on the same topic, generates now: |2009-06-01 23:18:23 +0100| dateString: |Jun 01, 2009 23:18| parsed: |2009-06-01 23:18:00 +0100| This is almost what I'm looking for, but I want to separate the day and time. NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"MMM dd, yyyy HH:mm"]; NSDate *now = [[NSDate alloc] init]; NSString

Difference between 'YYYY' and 'yyyy' in NSDateFormatter

北城余情 提交于 2019-12-16 22:13:09
问题 What is exact difference between 'YYYY' and 'yyyy'. I read in this link, it states that A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year. But when I try to use NSString *stringDate = @"Feb 28, 2013 05:30pm"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

NSDateFormatter wrong date

我是研究僧i 提交于 2019-12-14 04:17:17
问题 As simple as NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"dd/MM/yyyy"]; NSLog(@"Current date in event %@ %@",currentDate,[df stringFromDate:currentDate]); But in the log Current date in event 2013-10-01 22:00:00 +0000 02/10/2013 Why? 回答1: When you log an NSDate it always prints in UTC time. When you use stringFromDate: you get a date in local time unless you change the timezone of the date formatter. In this case you are in a timezone two hours ahead of UTC

DateFormatter.localizedString is broken for some of the dates

徘徊边缘 提交于 2019-12-14 04:04:12
问题 This is what I do when picker changes: extension Date { var fromCurrentToUTC: Date { return addingTimeInterval(-TimeInterval(TimeZone.current.secondsFromGMT())) } } var title = "--" if let date = datePickerView.date?.fromCurrentToUTC { title = DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .none) } print("-----") print(datePickerView.date!) print(title) print(TimeZone.current) print(datePickerView.date!.timeIntervalSince1970) dateTimeSegmentControl.setTitle(title,