【问题标题】:Mapping a strange datestring as an NSDate in Restkit在 Restkit 中将一个奇怪的日期字符串映射为 NSDate
【发布时间】:2013-12-07 08:19:59
【问题描述】:

我有一个包含开始和结束日期的JSON。但他们在JSON 中的样子是这样的

EndDate: "/Date(1375693200000+0200)/"
StartDate: "/Date(1375686000000+0200)/"

我知道您可以将NSDateFormatters 添加到您的RKEntityMapping,但我不知道该怎么做?我平时都是这样的

 NSDateFormatter *dateFormatter = [NSDateFormatter new];
        [dateFormatter  setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
        //dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

        [RKEntityMapping addDefaultDateFormatter:dateFormatter];

有人可以帮忙吗?

【问题讨论】:

    标签: ios iphone objective-c restkit nsdateformatter


    【解决方案1】:

    但是 json 中的字符串是没有日期的。似乎更像是一个时间间隔。尝试提取值 1375693200000 并创建具有时间间隔的日期

    NSTimeInterval timeInterval = 1375693200000;
    NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    

    【讨论】:

      【解决方案2】:

      您收到的日期是 ASP.NET JSON 日期。 RestKit 有专门针对此事的日期:RKDotNetDateFormatter。了解如何使用它here

      【讨论】:

        猜你喜欢
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 1970-01-01
        • 2020-03-15
        • 2018-05-14
        • 2013-06-15
        相关资源
        最近更新 更多