nsdateformatter

Nsdateformatter for specific language like Spanish

99封情书 提交于 2020-04-17 22:51:47
问题 My application is in 2 language one is English and other is Spanish. Now I receive timestamp from the server and I need to show date in "MMM dd, yyyy" formate. this is giving me "Dec 23, 2017" but when I convert it into Spanish then I need to show month name in Spanish. Can you please suggest do I specify 12 month name in Spanish as a short form or NSDateFormatter has this type of option. NSDate *date = [dateFormatter dateFromString:[[[webserviceDict valueForKey:@"CurrentWeekEarning"

Adding Time Offset in Swift

二次信任 提交于 2020-04-05 11:58:53
问题 I have a bunch of different show times in a database and want to display the correct time based on the users time zone by creating an offset. I'm getting the users time zone offset from GMT and converting that to hours first. NSTimeZone.localTimeZone().secondsFromGMT / 60 / 60 Then I need to find a way to add the hours to the date object.. that is where I/m struggling. let formatter = NSDateFormatter() formatter.dateFormat = "HH:mm" let date = formatter.dateFromString(timeAsString) println(

Adding Time Offset in Swift

北城以北 提交于 2020-04-05 11:58:04
问题 I have a bunch of different show times in a database and want to display the correct time based on the users time zone by creating an offset. I'm getting the users time zone offset from GMT and converting that to hours first. NSTimeZone.localTimeZone().secondsFromGMT / 60 / 60 Then I need to find a way to add the hours to the date object.. that is where I/m struggling. let formatter = NSDateFormatter() formatter.dateFormat = "HH:mm" let date = formatter.dateFromString(timeAsString) println(

NSDateFormatter not working properly?

心不动则不痛 提交于 2020-03-16 11:18:20
问题 My code , -(NSString *)trimDateStringInRequiredFormat:(NSString *)dateInString{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSDate *date = [dateFormatter dateFromString:dateInString]; [dateFormatter setDateFormat:@"hh:mm aaa"]; NSString *dateDisplay = [dateFormatter stringFromDate:date]; return dateDisplay; } The above worked properly when my date is 2012-06-06 12:00:00 and I got appropriate output like 12:00 AM. But

iOS中日期和字符串的相互转化

梦想与她 提交于 2020-03-02 12:41:29
例1、 从服务器段获取到的字符串转化为时间如: //网络请求获取的数据 NSString *time = @"495946429"; NSInteger num = [time integerValue]; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd"]; NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:num]; NSString *confromTimespStr = [formatter stringFromDate:confromTimesp]; NSLog(@"%@",confromTimespStr); 转化之后结果为: 1985-09-19 例2、如何如何将一个字符串如“ 20110826134106”装化为任意的日期时间格式,下面列举两种类型: NSString *string = @"20110826134106";

Date Format - time zone

无人久伴 提交于 2020-02-24 20:55:31
问题 I receive from the server a string with a date that looks like this: "2013-03-29T15:27:00Z". How can I format it and transform it into an NSDate? 回答1: Try this: [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *date = [formatter dateFromString:@"2013-03-29T15:27:00Z"]; 回答2: NSString *departTimeDate = @"2013-03-29T15:27:00Z";

NSDateFormatter - 1 day incorrect?

主宰稳场 提交于 2020-01-30 05:08:12
问题 I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"M/d/yyyy"]; NSDate *date = [dateFormatter dateFromString:@"10/7/2007"]; but when I output the date in an NSLog it has this: NSLog(@"Date:

NSDateFormatter - 1 day incorrect?

拈花ヽ惹草 提交于 2020-01-30 05:07:19
问题 I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"M/d/yyyy"]; NSDate *date = [dateFormatter dateFromString:@"10/7/2007"]; but when I output the date in an NSLog it has this: NSLog(@"Date:

Swift date formatting

牧云@^-^@ 提交于 2020-01-28 10:41:28
问题 I'm trying to pull a date string from a button and format is as a date to be store in CoreData. Here is my code: let dateStr = setDateBTN.titleLabel?.text let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM-dd-YYYY" let date:NSDate = dateFormatter.dateFromString(dateStr!)! If I do a println on dateStr I get the following: 03-10-2015 . Then if I immediately println on date I get: 2014-12-21 05:00:00 +0000 . Any ideas as to why the actual date is changing when I run it through

How to convert NSString to NSDate using NSDateFormatter?

限于喜欢 提交于 2020-01-24 21:35:07
问题 I getting the date from the webservice like "2012-07-03 07:26:48". I have saved in NSString after parsing from webservice. While convert the NSString to NSDate used below code, NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSString *dateStr = @"2012-07-03 07:26:48"; NSDate *date = [dateFormatter1 dateFromString:dateStr]; NSLog(@"Date : %@", date); The NSLog value is "2012-07-03 01:56:48 +0000"; The NSLog value is "2012