In Swift:
if you want to makeit as global variable see below code:
var Timestamp: String {
return "\(NSDate().timeIntervalSince1970 * 1000)"
}
Then, you can call it
println("Timestamp: \(Timestamp)")
The *1000 is for miliseconds, if you'd prefer, you can remove that. If keep it as an NSTimeInterval.
var Timestamp: NSTimeInterval {
return NSDate().timeIntervalSince1970 * 1000
}
In Objective C:
If your want to declare as symbolic constant see below code:
#define TimeStamp [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970] * 1000]
Then Call it like this:
NSString * timestamp = TimeStamp;
Or create a global method:
- (NSString *) timeStamp {
return [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970] * 1000];
}
Have a Note: The 1000 is to convert the timestamp to milliseconds. You can remove this if you prefer your timeInterval in seconds.