Objective-C 中的时间段

发布于 2025-01-05 07:17:20 字数 823 浏览 2 评论 0原文

在做一个小项目时,我收到了一些 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 技术交流群。

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

发布评论

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

评论(1

滥情稳全场 2025-01-12 07:17:20

我不完全确定你想用它做什么,但你会想看看:

  1. NSCalendar

  2. <一href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html" rel="nofollow">NSDateComponent

  3. <一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:

  1. NSCalendar

  2. NSDateComponents

  3. NSDate

If you give more information about what you're actually trying to achieve, we can explain how you'd use these.

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