Comments (10)
我在模拟器和真机都测试了一下,没有发现时区有变化的问题,你能详细描述一下或者确认你的测试环境吗?
from cxdatepickerview.
我用的是真机测试的,地区选的是北京。我测试发现是NSDate+CXCategory这里面的+ (NSDate *)date:(NSString *)datestr WithFormat:(NSString *)format 这个方法,当返回出的date和datestr就出现了8个小时的偏移,然后我不知道是不是其他的地方有调整回来,我去- (instancetype)initWithDateStyle:(CXDateStyle)datePickerStyle CompleteBlock:(void(^)(NSDate *date))completeBloc调用这个方法回调的时候,获取到的就是偏移过后的时间了。
from cxdatepickerview.
- (NSDate *)date:(NSString *)datestr WithFormat:(NSString *)format {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
NSLog(@"%@", [NSTimeZone localTimeZone]);
[dateFormatter setDateFormat:format];
NSDate *date = [dateFormatter dateFromString:datestr];
#if ! __has_feature(objc_arc)
[dateFormatter release];
#endif
return date;
}
这个方法里,我已经设定了时区是本地时区。打印结果如下:
2019-11-13 09:47:21.820334+0800 CXDatePickerView[95677:4135150] Local Time Zone (Asia/Shanghai (GMT+8) offset 28800)
2019-11-13 09:47:30.738968+0800 CXDatePickerView[95677:4135150] 选择的日期:2019-11-13 09:47
2019-11-13 09:47:30.739342+0800 CXDatePickerView[95677:4135150] Wed Nov 13 09:47:00 2019
from cxdatepickerview.
你能帮我打印一下你那边的信息吗?
from cxdatepickerview.
format __NSCFConstantString * @"yyyy-MM-dd HH:mm" 0x0000000102710120
datestr __NSCFString * @"2019-11-12 10:14" 0x0000000281101b60
NSMutableString NSMutableString
dateFormatter NSDateFormatter * 0x281101b30 0x0000000281101b30
date __NSTaggedDate * 2019-11-12 02:14:00 UTC 0xaea60e7155656a94
from cxdatepickerview.
这个是那个方法,我断点打印的数据
from cxdatepickerview.
po selectDate
2019-11-10 16:00:00 +0000
2019-11-13 10:17:58.603515+0800 Airport[1483:694060] Mon Nov 11 00:00:00 2019
这里是你的打印和返回出来我po出来的回调那个时间,我选择的是2019-11-11
from cxdatepickerview.
哦哦哦,我懂你的意思了。
2019-11-13 10:42:25.903905+0800 CXDatePickerView[97194:4185430] Local Time Zone (Asia/Shanghai (GMT+8) offset 28800)
2019-11-13 10:42:25.905723+0800 CXDatePickerView[97194:4185430] Local Time Zone (Asia/Shanghai (GMT+8) offset 28800)
(lldb) po selectDate
2019-11-13 02:42:00 +0000
(lldb) po dateString
2019-11-13 10:42
(lldb)
NSDate对象描述的是时间线上的一个绝对的值,和时区和国家无关的,直接打印都是0时区的,使用时一般是转成时间戳或者字符串。
from cxdatepickerview.
哦,这样的,我是直接使用的date。所以是这个问题吧,我转换一下吧,谢谢细心给我解答
from cxdatepickerview.
嗯嗯,很高兴能帮到你。
from cxdatepickerview.
Related Issues (15)
- 日时分 怎么选择额 HOT 2
- 最新版本0.2.0天数最大只有29天 HOT 1
- iOS14 适配 HOT 1
- 年月日显示间距有问题 HOT 2
- 随着时间的选择。headtitle也跟着改变
- 切换系统的日历比如 选择日本公历 ,同时设置最大时间为当前时间,会有越界崩溃 HOT 1
- 时间单位出现重叠 HOT 1
- 系统时间设置为12小时制时,超过12点将无法获取时间
- 帮我在 日时分那里增加可以选择 0日0时0分的可以不、 HOT 10
- 老铁,弹出在中间并且点击空白不可以DIMISS的有吗 HOT 1
- 年月选择器,点选月份会闪退 HOT 3
- 日 这个选择看不见了
- 分类名字冲突 HOT 1
- 请问,想在,年月日时分后,再添加秒,怎么加 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cxdatepickerview.