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就是当前的时间以字符串形式的展示
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就是当前的时间以字符串形式的展示
相关文章推荐
- iOS自定义弹窗(UIView)
- ISO中根据URL下载图片,请求图片
- ui-router使用方法
- hdoj-5301-Buildings
- 347. Top K Frequent Elements【M】【VIP】【字典排序】
- 347. Top K Frequent Elements
- [BS-17] iOS开发-Alpha,Hidden和Opaque区别
- Installation error: INSTALL_FAILED_UID_CHANGED解决方案
- 第九章 UITableView编辑模式笔记
- 限制UITextView输入字数(兼容iOS7)
- UIInterfaceOrientation和UIDeviceOrientation的区别
- UIGraphics 绘制饼图
- UE4 减少APK包的大小
- JDBC Request的用法
- iOS之UI学习-UITextField属性篇
- vue中v-bind:class动态添加class
- UIGraphics 向图片上写字
- 限制UITextField只能输入数字
- UITextView 文字莫名其妙垂直居中解决办法
- ${pageContext.request.contextPath} JSP取得绝对路径