解析特定时间格式

发布于 2024-12-04 10:51:56 字数 71 浏览 6 评论 0原文

我从 .NET Web 服务获取以下格式的时间/持续时间:PT12H30M

如何处理?

I am getting a time/duration from a .NET web service in this format: PT12H30M

How can this be handled?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

裂开嘴轻声笑有多痛 2024-12-11 10:51:56

当您定义用于解析日期的格式字符串时,您可以使用 UTS #35 日期格式模式 定义传入数据的样子。 PT 看起来像是合法的时区缩写。您将需要根据分钟和小时是否用零填充来摆弄它。

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

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];
白鸥掠海 2024-12-11 10:51:56

看看 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.

征棹 2024-12-11 10:51:56

创建一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文