Date Formate Patterns相关整理

来源:互联网 发布:淘宝改一口价的技巧 编辑:程序博客网 时间:2024/06/05 19:58
//实例化一个NSDateFormatter对象NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];//设定时间格式,这里可以设置成自己需要的格式[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//用[NSDate date]可以获取系统当前时间NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];//输出格式为:2010-10-27 10:22:13
UIDatePicker *datePicker=[[UIDatePicker alloc]initWithFrame:CGRectMake(0, 38, [UIScreen mainScreen].bounds.size.width, 162)];    datePicker.datePickerMode = UIDatePickerModeDateAndTime;    if (self.fontColor) {        [commitBtn setTitleColor:self.fontColor forState:UIControlStateNormal];        [cancelBtn setTitleColor:self.fontColor forState:UIControlStateNormal];    }    //设置显示格式    //默认根据手机本地设置显示为中文还是其他语言    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为中文显示    datePicker.locale = locale;    //当前时间创建NSDate    NSDate *localDate = [NSDate date];    //在当前时间加上的时间:格里高利历    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];    //设置时间    [offsetComponents setYear:0];    [offsetComponents setMonth:0];    [offsetComponents setDay:5];    [offsetComponents setHour:20];    [offsetComponents setMinute:0];    [offsetComponents setSecond:0];    //设置最大值时间    NSDate *maxDate = [gregorian dateByAddingComponents:offsetComponents toDate:localDate options:0];    //设置属性    datePicker.minimumDate = localDate;    datePicker.maximumDate = maxDate;

Date Formate Patterns