Time stamp used once, summed up:
1. Obtain a timestamp under terminal:
Date +%s
The original to be in the server-side hanging documents, convenient for developers to download, with time stamp as a file name to distinguish.
2. Get the timestamp under the program:
NSDate * Nowdate = [NSDate date]; NSLog (@ "Current time is: Nowdate =%@\n", nowdate); Nstimeinterval time = [[NSDate date]timeintervalsince1970]; NSLog (@ "timestamp: date =%ld\n", (long) time);
3. Convert the date to any format based on the timestamp:
NSDateFormatter * Dateformatter = [[NSDateFormatter alloc]init]; [Dateformatter setdateformat:@ "HH:mm:ss"];//here, you can write any date format you want to write YYYY-MM-DD hh:mm:ss nsdate * lastdate = [nsdate dateWithTimeIntervalSince1970: (long) time]; NSString * newstr= [dateformatter stringfromdate:lastdate]; NSLog (@ "newdate =%@\n", newstr);
over! QQ Group: 461093715
IOS time Stamp