解析特定时间格式
我从 .NET Web 服务获取以下格式的时间/持续时间:PT12H30M
如何处理?
I am getting a time/duration from a .NET web service in this format: PT12H30M
How can this be handled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您定义用于解析日期的格式字符串时,您可以使用 UTS #35 日期格式模式 定义传入数据的样子。 PT 看起来像是合法的时区缩写。您将需要根据分钟和小时是否用零填充来摆弄它。
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.
看看 NSDateFormatter< /a>,可以使用 特定语法。解析结果是一个标准的 NSDate。
Take a look at NSDateFormatter, which can parse dates with a user-specified format using particular syntax. Parse result is a standard NSDate.
创建一个 NSDateFormatter 实例,配置一个描述时间格式的格式字符串,然后使用 -dateFromString: 方法将从 Web 服务获取的时间转换为 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.