开发者

parsing a particular time format

开发者 https://www.devze.com 2023-04-04 08:37 出处:网络
I am getting a time/d开发者_StackOverflow中文版uration from a .NET web service in this format: PT12H30M

I am getting a time/d开发者_StackOverflow中文版uration from a .NET web service in this format: PT12H30M

How can this be handled?


When you define the format string for parsing a date you use the UTS #35 Date Format Patterns to define what the incoming data looks like. PT looks like a legitimate timezone abbreviation. You will want to fiddle with this depending on whether the minutes and hours are zero-padded or not.

NSString *dateString = @"PT12H30M";
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ZZhh'H'mm'M'"];
NSDate date = [dateFormatter stringFromDate:dateString];


Take a look at NSDateFormatter, which can parse dates with a user-specified format using particular syntax. Parse result is a standard NSDate.


Create an instance of NSDateFormatter configured with a format string the describes the time format, and then use the -dateFromString: method to translate the time you get from the web service into a NSDate object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号