項目中為了與Android相配合.要獲取到時間戳裡的毫秒單位:
獲取方法:
UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
如果你想格式化輸出 可以:
NSDateFormatter * formatter = [[NSDateFormatter alloc ] init]; [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"]; NSString *date = [formatter stringFromDate:[NSDate date]]; NSString *timeLocal = [[NSString alloc] initWithFormat:@"%@", date]; NSLog(@"%@", timeLocal);