PHP在Objective C / iPhone中的strtotime

时间:2010-08-05 05:58:35

标签: iphone objective-c strtotime

在Objective C / iPhone中是否存在与PHP的strtotime等效(或模糊相似)?

strtotime可以例如理解下面的时间表达式(来自php文档):

  • echo strtotime(“now”),“\ n”;
  • echo strtotime(“2000年9月10日”),“\ n”;
  • echo strtotime(“+ 1天”),“\ n”;
  • echo strtotime(“+ 1周”),“\ n”;
  • echo strtotime(“+ 1周2天4小时2秒”),“\ n”;
  • echo strtotime(“下周四”),“\ n”;
  • echo strtotime(“上周一”),“\ n”;

3 个答案:

答案 0 :(得分:1)

[NSDate +dateWithString]做你想要的,我想。

答案 1 :(得分:0)

以下是第一个和第二个查询的一些代码:

  • echo strtotime(“now”),“\ n”;
  • echo strtotime(“2000年9月10日”),“\ n”;
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"dd MMM yyyy"];
    NSDate *now = [[NSDate alloc] init];
    NSString *dateString = [format stringFromDate:now];
    NSLog(@"The time: %@", dateString);

    NSDate *parsed = [format dateFromString:@"10 Sep 2000"];
    NSLog(@"The time: %@", [format stringFromDate:parsed]);

显然,分配的对象需要释放。

这是一篇可能有助于其他人的文章:

http://www.drobnik.com/touch/2009/05/adding-days-to-nsdate

答案 2 :(得分:0)

我突然想起了“PHPJS”项目。这里有一个strtotime的javascript端口:

http://phpjs.org/functions/strtotime:554

我还没有测试它(这意味着,将它移植到Objective C函数或类似功能),所以我不确定它与原始strtotime相比实际执行得有多好。可能有时间检查一下......