如何比较iphone中的两个日期?

2023-10-23移动开发问题
0

本文介绍了如何比较iphone中的两个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想比较今天的日期和来自我的数据库的其他日期.例如,2011-03-25 与 2011-02-25 比较

I want to compare the todays date and other date coming from my database. For example, 2011-03-25 compare it with 2011-02-25

由于 NSDateFormatter 需要 NSDdate 数据类型,我如何格式化我的数据库日期?

How can i formate my database date as the NSDateFormatter require NSDdate datatype ?

推荐答案

Cocoa 有两种方法:

在 NSDate 中

– isEqualToDate:
– 较早日期:
– 稍后日期:
– 比较:

– isEqualToDate:
– earlierDate:
– laterDate:
– compare:

当你使用 - (NSComparisonResult)compare:(NSDate *)anotherDate 时,你会得到其中之一:

When you use - (NSComparisonResult)compare:(NSDate *)anotherDate ,you get back one of these:

The receiver and anotherDate are exactly equal to each other, NSOrderedSame
The receiver is later in time than anotherDate, NSOrderedDescending
The receiver is earlier in time than anotherDate, NSOrderedAscending.

有关更多信息,请阅读 SO 帖子

for more read the SO post

浏览一下博文,有很多与日期相关的实用功能.

Just go through the blog post, there are many date related utility functions.

http://arstechnica.com/apple/guides/2010/03/how-to-real-world-dates-with-the-iphone-sdk.ars/2

这篇关于如何比较iphone中的两个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7