Make an NSURL with an encoded plus (+)

前端 未结 7 1185
灰色年华
灰色年华 2021-02-14 01:39

I need to pass a timestamp with a timezone offset in a GET request, e.g.,

2009-05-04T11:22:00+01:00

This looks like a two arguments

7条回答
  •  清酒与你
    2021-02-14 02:04

    Thought I may as well provide my workaround as an answer, as I don't think there's a good solution to the original problem.

    The plus sign (+) is completely valid in a URL, so my solution was to convert the time to GMT and remove the timezone/DST offset from the string. I'll leave it as an exercise for the reader to determine the value of secondsFromGMT below as, in my case, it's always the same because I'm only interested in timestamps generated by a web server.

    NSString *gmtWhen = [[self descriptionWithCalendarFormat:nil
                               timeZone:[NSTimeZone
                               timeZoneForSecondsFromGMT:secondsFromGMT
                         ] locale:nil] stringByReplacingOccurrencesOfString:@" +0000" withString:@""];
    

提交回复
热议问题