I need a way to get the current date converted into epoch time e.g: 12343215325
I've tried so many things, but since im new i might be doing stupid stuff.
Any help is appreciated.
Thank you.
I need a way to get the current date converted into epoch time e.g: 12343215325
I've tried so many things, but since im new i might be doing stupid stuff.
Any help is appreciated.
Thank you.
This can be done with the NSDate class:
NSDate *now = [NSDate date];
NSTimeInterval nowEpochSeconds = [now timeIntervalSince1970];
Note that timeIntervalSince1970
is an instance method that returns an NSTimeInterval
. However, if we look at the definition of NSTimeInterval
:
typedef double NSTimeInterval;
So we simply have a double
holding current seconds since 00:00:00 on 1 Jan 1970, so output format is the same as with a double
format. This value is precise to sub-milliseconds so we can get milliseconds-epoch-time by multiplying by 1000.
in c declare a tm structure struct tm yourtm; fill in the tm structure with the current local date and time. then call mktime ( &yourtm ) and it will return the number of seconds since Jan 1, 1970 in GMT.