How do you convert any given date to milliseconds? For example, 2014-01-23 to timestamp conversion.
NSDate *date = [dateFormatter dateFromString:@"2014-01-23"];
NSLog(@"date=%@",date);
NSTimeInterval interval = [date timeIntervalSince1970];
NSLog(@"interval=%f",interval);
NSDate *methodStart = [NSDate dateWithTimeIntervalSince1970:interval];
[dateFormatter setDateFormat:@"yyyy/mm/dd "];
NSLog(@"result: %@", [dateFormatter stringFromDate:methodStart]);
Output result: 1970/30/01
The converter on this page converts timestamps in seconds (10-digit), milliseconds (13-digit) and microseconds (16-digit) to readable dates. How to get the current epoch time in ...
These examples are returning timestamp in seconds, although some of the languages are returning timestamp in milliseconds. These examples are showing how to get current date and time that could be presented to the end-user. These examples are showing how to convert timestamp - either in milliseconds or seconds to human readable form.
A Core Data timestamp is the number of seconds (or nanoseconds) since midnight, January 1, 2001, GMT (see CFAbsoluteTime ). The difference between a Core Data timestamp and a Unix timestamp (seconds since 1/1/1970) is 978307200 seconds. The current Core Data timestamp is 682616486 or in nanoseconds: 682616486000000000
In Shortcuts, you can convert from the UNIX time format to a more human-readable time format by using the Date, Adjust Date, and Format Date actions. The Date action is set to 00:00:00 UTC Jan 1, 1970. Add the UNIX Time variable to the UTC date to get the adjusted date. Next, use Format Date to remove the time component (as they are all 00:00:00).
Convert the current date/time to a timestamp:
// current date and time
let someDate = Date()
// time interval since 1970
let myTimeStamp = someDate.timeIntervalSince1970
See also
Have it a try. "mm" stands for minute while "MM" stands for month.
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init] ;
[dateFormatter setDateFormat:@"yyyy-MM-dd"] ;
NSDate *date = [dateFormatter dateFromString:@"2014-01-23"] ;
NSLog(@"date=%@",date) ;
NSTimeInterval interval = [date timeIntervalSince1970] ;
NSLog(@"interval=%f",interval) ;
NSDate *methodStart = [NSDate dateWithTimeIntervalSince1970:interval] ;
[dateFormatter setDateFormat:@"yyyy/MM/dd "] ;
NSLog(@"result: %@", [dateFormatter stringFromDate:methodStart]) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With