nsdateformatter

Finding time between dates in Swift [duplicate]

痴心易碎 提交于 2019-12-24 13:41:24
问题 This question already has answers here : Getting the difference between two NSDates in (months/days/hours/minutes/seconds) (18 answers) Closed 4 years ago . Hi Im trying to work out the time between two dates using UIpickers and I am lost. I cannot fathom where to go to on this to get the value to plug into the label. Im not sure if I should use components or before the comparison or just after to put it in the label. Thanks for any pointers. let calendar = NSCalendar.currentCalendar() let

Incorrect time string with NSDateFormatter with Daylight Saving Time

久未见 提交于 2019-12-24 11:37:23
问题 I'm using CET as my default timezone in my application. In Germany Daylight saving time will start from 29 March 2015 . Now I'm doing some testing to see if my dates will be converted correctly in the future. I used following code to test it. NSTimeZone *timeZone = [NSTimeZone timeZoneWithAbbreviation:@"CET"]; [NSTimeZone setDefaultTimeZone:timeZone]; NSDate *now = [NSDate date]; // 10 Feb, 2015 NSDate *dateAfter29March = [now dateByAddingMonths:2]; // 10 April, 2015 NSDateFormatter

Crash when converting string to date

﹥>﹥吖頭↗ 提交于 2019-12-24 07:43:33
问题 In my app I DO NOT want to use the local time on the phone. I want to get the current time in GMT. To do this I have a date formatter with time zone set to GMT. I then do the following to get back the current time: NSString *dateOne = [df stringFromDate:[NSDate date]]; NSDate *date1 = [df dateFromString:dateOne]; My app gets an EXC_BAD_ACCESS though on the dateFromString call. I checked the returned value from dateOne and it's format matches the dateformatters. What am I doing wrong? Is there

Combining time and date in ISO8601 format string using Swift

久未见 提交于 2019-12-24 03:44:11
问题 I have two texfields representing date and time from the date picker, but when I parse the string only the date is displayed. I would like to combine date and time into a string in ISO8601 format (e.g. 2015-06-11T00:00:00.000Z ) and send it to the server. 回答1: You can do it using NSCalendar method dateBySettingHour as follow: Xcode 8.2.1 • Swift 3.0.2 let df = DateFormatter() df.calendar = Calendar(identifier: .iso8601) df.locale = Locale(identifier: "en_US_POSIX") df.dateFormat = "yyyy-MM-dd

Invalid parameter not satisfying: date

痴心易碎 提交于 2019-12-24 00:28:12
问题 I'm having an issue coming in from Crashlytics. I have debugging parameters on so I am seeing what parameters there are. datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]]; NSLog(@"Time: %@",startTimeString); NSLog(@"Date: %@", appointment.date); [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];

iOS 10 bug? NSDate hour description with Japan region and 24-Hour Time off

混江龙づ霸主 提交于 2019-12-23 19:10:30
问题 This seems like an iOS 10 bug. It is OK in iOS 8 and 9. The hour description is wrong for [NSDate date].description. It is appending the 24 hour description and 12 hour description. I am not using NSDateFormatter. Just the default settings. On a real iOS 10 device, in Settings: Set Region to Japan in Settings > General > Language & Region > Region Formats > Region Set 24-Hour Time Off in Settings > General > Date & Time > 24-Hour Time Then with: NSLog(@"Date is %@", [NSDate date].description)

AM/PM issue in NSDateFormatter

筅森魡賤 提交于 2019-12-23 16:20:02
问题 I write below code to convert one date format into another dateformat. But AM string works and PM did not work . Please help- dateTime=@"2013-01-24 18:30 PM"; //dateTime=@"2013-01-24 06:30 AM"; NSDateFormatter *dtFormatter=[[NSDateFormatter alloc]init]; [dtFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"]; NSDate *AptDate=[dtFormatter dateFromString:dateTime]; [dtFormatter setDateFormat:@"MMM dd,yyyy hh:mm a"]; NSString *strDate=[dtFormatter stringFromDate:AptDate]; Here I get AptDate variable

Convert NSString to NSDate with string format “Sun, 08 Jan 2012 13:57:38 +0000”

送分小仙女□ 提交于 2019-12-23 12:16:23
问题 I actually retrieve string date with the format "Sun, 08 Jan 2012 13:57:38 +0000" For that I use the dateFormat "EEE, dd MMM yyyy HH:mm:ss ZZZ" But it doesn't work... NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"]; NSLog(@"%@",[dict objectForKey:@"created_at"]); NSDate *dateFromString = [dateFormatter dateFromString:[dict objectForKey:@"created_at"]]; NSLog(@"%@",dateFromString); For the first NSLog it displays

How to format DateTime to local users locale in short time format using MonoTouch

只谈情不闲聊 提交于 2019-12-23 11:59:50
问题 I've tried multiple approaches, this is one of them: System.Globalization.DateTimeFormatInfo format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat; return dt.Value.ToString (format.ShortTimePattern); The problem with this one is that .NET 3.5 returns a "." as the time seperator which is most likely a bug (since my Norwegian locale uses a colon): .NET (3.5) formats times using dots instead of colons as TimeSeparator for it-IT culture? I also looked here: Retrieving current

Ordinary Date Format “13th June 2007” in Swift [duplicate]

拜拜、爱过 提交于 2019-12-23 10:26:15
问题 This question already has answers here : Ordinal Month-day Suffix Option for NSDateFormatter setDateFormat (15 answers) Closed 3 years ago . hello can any one point me to hoe make a date format that looks like this: 13th June 2007. Notice the day has the word "th". I want to add that in my format. Thanks! 回答1: Updated for Swift 3 You can do something like this which is locale safe. let calendar = Calendar.current let date = Date() let dateComponents = calendar.component(.day, from: date) let