Objective-C 中的时间段
在做一个小项目时,我收到了一些 Java 代码,我应该将它们重写为 Objective-C(准确地说是 iPhone)。我遇到了这段代码:
public class Period {
private org.joda.time.Period jodaPeriod;
public Period(org.joda.time.Period jodaPeriod) {
Validate.isTrue(PeriodType.standard().equals(jodaPeriod.getPeriodType()),
"The jodaPeriod argument must be a standard type period");
this.jodaPeriod = jodaPeriod;
}
public Period(int months) {
this(new org.joda.time.Period(months / 12, months % 12, 0, 0, 0, 0, 0, 0));
}
public Period(int years, int months) {
this(new org.joda.time.Period(years, months, 0, 0, 0, 0, 0, 0));
}
//some other code
}
经过快速研究,我了解了 JodaTime period
的基础知识,但我仍然不知道如何在 Objective-C
中做到这一点。我读过有关 CMTime
的内容,但这并不是我真正想要的。
谢谢,任何帮助将不胜感激。 :)
Doing a small project I have received some Java code that I should rewrite into Objective-C(for iPhone to be precise). I came across this piece of code:
public class Period {
private org.joda.time.Period jodaPeriod;
public Period(org.joda.time.Period jodaPeriod) {
Validate.isTrue(PeriodType.standard().equals(jodaPeriod.getPeriodType()),
"The jodaPeriod argument must be a standard type period");
this.jodaPeriod = jodaPeriod;
}
public Period(int months) {
this(new org.joda.time.Period(months / 12, months % 12, 0, 0, 0, 0, 0, 0));
}
public Period(int years, int months) {
this(new org.joda.time.Period(years, months, 0, 0, 0, 0, 0, 0));
}
//some other code
}
After a quick research I got the basics of the JodaTime period
, but I still don't know how to do that in Objective-C
. I've read about CMTime
, but it's not really what I was looking for.
Thank you, any help would be greatly appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全确定你想用它做什么,但你会想看看:
NSCalendar
<一href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html" rel="nofollow">NSDateComponent
<一href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html" rel="nofollow">NSDate
如果您给出有关您实际想要实现的目标的更多信息,我们可以解释您如何使用它们。
I'm not entirely sure what you're trying to use this for, but you'll want to look at:
NSCalendar
NSDateComponents
NSDate
If you give more information about what you're actually trying to achieve, we can explain how you'd use these.