Giter Site home page Giter Site logo

Comments (10)

CXTretar avatar CXTretar commented on June 21, 2024

我在模拟器和真机都测试了一下,没有发现时区有变化的问题,你能详细描述一下或者确认你的测试环境吗?

from cxdatepickerview.

carry1024 avatar carry1024 commented on June 21, 2024

我用的是真机测试的,地区选的是北京。我测试发现是NSDate+CXCategory这里面的+ (NSDate *)date:(NSString *)datestr WithFormat:(NSString *)format 这个方法,当返回出的date和datestr就出现了8个小时的偏移,然后我不知道是不是其他的地方有调整回来,我去- (instancetype)initWithDateStyle:(CXDateStyle)datePickerStyle CompleteBlock:(void(^)(NSDate *date))completeBloc调用这个方法回调的时候,获取到的就是偏移过后的时间了。

from cxdatepickerview.

CXTretar avatar CXTretar commented on June 21, 2024
  • (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.

CXTretar avatar CXTretar commented on June 21, 2024

你能帮我打印一下你那边的信息吗?

from cxdatepickerview.

carry1024 avatar carry1024 commented on June 21, 2024

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.

carry1024 avatar carry1024 commented on June 21, 2024

这个是那个方法,我断点打印的数据

from cxdatepickerview.

carry1024 avatar carry1024 commented on June 21, 2024

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.

CXTretar avatar CXTretar commented on June 21, 2024

哦哦哦,我懂你的意思了。
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.

carry1024 avatar carry1024 commented on June 21, 2024

哦,这样的,我是直接使用的date。所以是这个问题吧,我转换一下吧,谢谢细心给我解答

from cxdatepickerview.

CXTretar avatar CXTretar commented on June 21, 2024

嗯嗯,很高兴能帮到你。

from cxdatepickerview.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.