I have found many timestamp transformations, and they all work, but the fact is that when I put my code in a date text form, I always go 4 months ahead.
It pulls the current day of the week, date and time. I have it installed this way, because I select the day using the DateTime Picker. This is just my viewDidLoad to pull today's date.
NSDate *myDate = [[NSDate alloc] init]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"cccc, MMMM dd, YYYY, hh:mm aa"]; NSString *prettyVersion = [dateFormat stringFromDate:myDate]; date.text = prettyVersion;
Now there is a time stamp conversion to accept prettyVersion in timeIntervalSince1970
NSDate *startdates = [dateFormat dateFromString:prettyVersion]; NSLog(@"Timestamp %0.0f",[startdates timeIntervalSince1970]);
NSLog displays "Timestamp 1356317580", which when converted - Mon, 24 Dec 2012 02:53:00 GMT
Now i can do it
NSLog(@"Timestamp2 %0.0f",[myDate timeIntervalSince1970]);
and get the correct timestamp.
So where did I mess around.
unix-timestamp ios objective-c
Duny
source share