您的位置:首页 > 产品设计 > UI/UE

UIDatePicker转为汉字,并且显示年月日

2016-05-09 15:37 483 查看
UIDatePicker *date = [[UIDatePickeralloc]initWithFrame:CGRectMake(0,50,
brank.frame.size.width,100)];

[brank addSubview:date];

date.locale = [[NSLocalealloc]initWithLocaleIdentifier:@"zh_CN"];

date.datePickerMode =UIDatePickerModeDate;

拿到的时间有8小时的时差

NSTimeZone *zone1 = [NSTimeZone
systemTimeZone];

NSInteger interval1 = [zone1
secondsFromGMTForDate:self.date.date];

NSDate *localeDate1 = [self.date.date
dateByAddingTimeInterval:interval1];

NSString *timeSp1 = [NSString
stringWithFormat:@"%ld",(long)[localeDate1
timeIntervalSince1970]];

NSInteger after = [timeSp1
integerValue] - 28800;

NSDateFormatter *formatter = [[NSDateFormatter
alloc]init];

formatter.dateStyle =
kCFDateFormatterMediumStyle;

formatter.timeStyle =
kCFDateFormatterShortStyle;

formatter.dateFormat =
@"YYYY-MM-dd HH:mm";

NSDate *new = [NSDate
dateWithTimeIntervalSince1970:after];

NSString *newString = [formatter
stringFromDate:new];

newString就是当前的时间以字符串形式的展示
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: