在12小时或24小时格式的NSDateComponent ?

时间:2022-08-21 20:11:12

Is the hour component of NSDateComponent in a 12h or 24h format? I cannot find anything about this in the documentation...

NSDateComponent的小时组件是12h还是24h格式?我在文件中找不到任何关于这个的东西……

1 个解决方案

#1


26  

It's 24 hours, on the gregorian calendar.

在公历上是24小时。

Why? The documentation doesn't say it explicitly; however, it does state that the values are for whatever calendar is used. am/pm is just a different notation -- countries using am/pm still have 24 hours per day, they are just writing if differently.

为什么?文件中没有明确说明;但是,它确实声明值适用于所使用的任何日历。am/pm只是一个不同的符号——使用am/pm的国家仍然每天有24小时,他们只是在写不同的东西。

Also, if you look at the available unit constants, you will notice there there is no "am/pm" constant. Again, that's because am/pm is a localized notation, not a property of the gregorian calendar.

此外,如果您查看可用的单位常量,您将注意到没有“am/pm”常量。这是因为am/pm是一个局部性的符号,而不是公历的属性。

EDIT: if you are asking this because you want to output a time in readable form, don't use NSDateComponents -- use NSDateFormatter.

编辑:如果您想要以可读的形式输出时间,那么不要使用NSDateComponents——使用NSDateFormatter。

#1


26  

It's 24 hours, on the gregorian calendar.

在公历上是24小时。

Why? The documentation doesn't say it explicitly; however, it does state that the values are for whatever calendar is used. am/pm is just a different notation -- countries using am/pm still have 24 hours per day, they are just writing if differently.

为什么?文件中没有明确说明;但是,它确实声明值适用于所使用的任何日历。am/pm只是一个不同的符号——使用am/pm的国家仍然每天有24小时,他们只是在写不同的东西。

Also, if you look at the available unit constants, you will notice there there is no "am/pm" constant. Again, that's because am/pm is a localized notation, not a property of the gregorian calendar.

此外,如果您查看可用的单位常量,您将注意到没有“am/pm”常量。这是因为am/pm是一个局部性的符号,而不是公历的属性。

EDIT: if you are asking this because you want to output a time in readable form, don't use NSDateComponents -- use NSDateFormatter.

编辑:如果您想要以可读的形式输出时间,那么不要使用NSDateComponents——使用NSDateFormatter。