在iPhone上的日期字符串中,我使用什么格式字符串作为毫秒? [英] What format string do I use for milliseconds in date strings on iPhone?

查看:113
本文介绍了在iPhone上的日期字符串中,我使用什么格式字符串作为毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以包含毫秒的格式解析字符串。我使用什么格式字符串来获取正确的日期值?

I'm required to parse strings in a format that includes milliseconds. What format string do I use to get the right date value?

例如,假设我有一个包含以下值的字符串:2011-06-23T13:13: 00.000

For example, suppose I have a string with the following value: "2011-06-23T13:13:00.000"

我在下面的代码中传递给我的NSDateFormatter的格式字符串是什么?

What format string do I pass to my NSDateFormatter in the following code?

NSString *dateValue = @"2011-06-23T13:13:00.000";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSString *formatString = @"yyyy-MM-dd'T'HH:mm:ss.???";
[formatter setDateFormat:formatString];
NSDate *date = [formatter dateFromString:dateValue];

我用什么代替???在上面的代码?

What do I use in place of ??? in the code above?

推荐答案

根据 SSS //unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns\">各种代码区域设置数据标记语言规范

It's SSS, per the Unicode Locale Data Markup Language spec.

"yyyy-MM-dd'T'HH:mm:ss.SSS"

更一般地,使用任意数量的大写S字符来获得一秒分数组件中的那么多小数位。 (例如, ss.S 将显示最接近的十分之一秒的时间。)

More generally, use any number of upper-case S characters to get that many decimal places in the fractions-of-a-second component. (So ss.S will show the time to the nearest tenth of a second, for example.)

这篇关于在iPhone上的日期字符串中,我使用什么格式字符串作为毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆