Getting current time in milliseconds Cocos2d

后端 未结 5 2028
误落风尘
误落风尘 2021-01-06 08:32

I\'ve tried to google around but I still can\'t find the best answer.

All I want is very simple, I just want to get the current time in milliseconds.

How can

5条回答
  •  自闭症患者
    2021-01-06 08:59

    To get only milliseconds

    NSDate* date = [NSDate date];
    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"ss"];
    
    NSString* str = [formatter stringFromDate:date];
    
    float seconds = str.intValue;
    
    float miliSeconds = seconds / 1000; // HERE is your answer
    

    If you want to get full time format replace

    [formatter setDateFormat:@"hh:mm:ss"];
    

提交回复
热议问题