Tag: nsdateformatter

如何在Swift for iOS中使用NSDateFormatter格式化date?

我试图parsing这个date“2016年6月18日星期六”到“18/06/2016”我知道这可以使用正则expression式的方法,但我不知道如何得到一个输出使用。 在swift中使用NSDateFormatter的方法将是首选

date没有以正确的方式显示

我有一些7 UILabels将显示如下所示的date: Jan,2016 (label) (button) < **29Dec 30Dec 31Dec 1Jan 2Jan 3Jan 4Jan** >(Button) 另外我有两个箭头UIButton在两边,当用户可以移动到倒退date或以前的date。 我有一个标签显示当前的月份,根据我的date显示 这是我的完整代码: Viewcontroller.h @property (weak, nonatomic) IBOutlet UILabel *flabel; @property (weak, nonatomic) IBOutlet UILabel *slabel; @property (weak, nonatomic) IBOutlet UILabel *tlabel; @property (weak, nonatomic) IBOutlet UILabel *folabel; @property (weak, nonatomic) IBOutlet UILabel *fivlabel; @property (weak, nonatomic) IBOutlet UILabel *sixlabel; @property […]

NSDateFormatter以“MMM dd yyyy”格式格式化服务器响应

我试图编写一个方法来转换从2016-08-04T00:00:01.000Z格式的服务器返回的date。 我的方法定义如下: – (NSString *)convertDate:(NSString *)dateString { NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZ"; NSDate *yourDate = [dateFormatter dateFromString:dateString]; dateFormatter.dateFormat = @"MMM dd yyyy"; NSLog(@"%@",[dateFormatter stringFromDate:yourDate]); NSString *str = [dateFormatter stringFromDate:yourDate]; return str; } 我一直有NSDateFormatter问题,有人可以帮我这个。 我希望方法返回string,如Aug 04, 2016 。 提前致谢。

如何在swift 2中更改date格式化程序?

我知道如何将date转换为string和stringdate的基本知识。 但是我面临以下问题: dateAsString = "2016/12/31" 我想将这个string转换为 date和string格式,位置更改为12/31/2016 。 请帮忙

与stringWithFormat问题

请如何使我的stringWithFormat / initWithFormat显示am / pm而不是24小时,即使用户从pickerviewerselectam / pm? 当用户select时间; 例如4:15 pm,而不是显示4:15 pm作为确认,而是显示16:15。 下午4:15我要。 请帮忙!! -(IBAction)datePickerValueChanged:(id)sender { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; [dateFormatter setDateFormat:@"h:mm:ss a"]; NSString *strDate = [dateFormatter stringFromDate:self.pick.date]; dateArray = [strDate componentsSeparatedByString:@":"]; NSDate *current = [NSDate date]; NSString *currentTime = [dateFormatter stringFromDate:current]; NSArray *currArray = [currentTime componentsSeparatedByString:@":"]; curr = [currArray[0] […]

如何比较两次从NSDate。 在比较时返回ndate。 #debug我的代码

这里是代码: // get current date/time NSDate *today = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // display in 12HR/24HR (ie 11:25PM or 23:25) format according to User Settings [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; [dateFormatter setDateFormat:@"HH:mm:ss"]; NSString *currentTime = [dateFormatter stringFromDate:today]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@"AM" withString:@""]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@"PM" withString:@""]; currentTime = [currentTime stringByReplacingOccurrencesOfString:@" " withString:@""]; NSDateFormatter […]

需要关于NSDateFormatter的帮助

我只想要像“29-10-2014”这样的date,没有时间,所以我做了这个 NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"dd-MM-yyyy"]; NSString *sDate = [df stringFromDate:date]; 如果我loginsDate我正在得到完美的结果。 但我不想要NSString我想要的date对象,在这里做我做的是 NSDate *theDate = [df dateFromString:sDate]; 现在我正在2014-10-29 19:00:00 +0000我只想要29-10-2014 。

在iOS文档中使用rfc3339dateFormatter作为示例之后,dateFromString返回nil

我想通过parsing以下方式从NSString获取NSDate: NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [rfc3339DateFormatter setLocale:enUSPOSIXLocale]; [rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; [rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString *createdString = [NSString stringWithFormat:@"2014-08-27T17:10:36.000+05:30"]; NSDate *createdDate = [rfc3339DateFormatter dateFromString:createdString]; 这里createdDate被返回为零。 我在这里错过了什么? 也请澄清我的timeZone和区域设置的正确使用。

date格式化问题在ObjC中

我需要将datestring“2015-03-10 00:00:00.000”(来自Web服务的string)转换为NSDate。 我已经使用这样的代码 NSDateFormatter *fromDateFormat = [[NSDateFormatter alloc] init]; [fromDateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *outputDate = [fromDateFormat dateFromString:@"2015-03-10 00:00:00.000"]; outputDate是零。 我尝试没有最后三个零,它正在工作。 但是我不能删除那个零,因为它来自一个服务。

在“GMT”时区在sqlite数据库中保存date

我正在使用Core-Data来存储date时间对象。 例如。 2015-07-28T07:16:52+0000这是GMT时区ISO格式的date。 但是当我在数据库中保存这个date NSString* dateString=@"2015-07-28T07:16:52+0000"; NSDateFormatter* dateTimeformatter=[[NSDateFormatter alloc] init]; [dateTimeformatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; [dateTimeformatter dateFromString:dateString]; 我在数据库中看到的结果date是2015-07-28 12:46:52 根据我的设备的时区在IST 我试图在dateFormatter中设置时区,但同样的响应 NSString* dateString=@"2015-07-28T07:16:52+0000"; NSDateFormatter* dateTimeformatter=[[NSDateFormatter alloc] init]; [dateTimeformatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; [dateTimeformatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; [dateTimeformatter dateFromString:dateString]; 即使将[NSDate date]直接保存在数据库中,它也会根据设备的时区保存转换的date。 为什么Core-data不考虑NSDateFormatter的时区? 任何人都可以告诉我如何可以将数据库中的dateGMT保存在数据库中,而不pipe我的设备的时区?