- One, the method of conversion is
- NSString *timesp = [NSString stringwithformat:@"%d", (long) [Localedate timeIntervalSince1970]];
- NSLog (@"timesp:%@", TIMESP); //timestamp value
- Second, convert the acquired time into the current time
- NSDate *datenow = [NSDate Date]; //Time now, you can output to see what the format is
- Nstimezone *zone = [Nstimezone systemtimezone];
- Nsinteger interval = [zone Secondsfromgmtfordate:datenow];
- NSDate *localedate = [Datenow datebyaddingtimeinterval:interval];
- NSLog (@"%@", localedate);
- 3. Ways to convert timestamps into time
- NSDate *CONFROMTIMESP = [nsdate dateWithTimeIntervalSince1970:1363948516];
- NSLog (@"1363948516 =%@", CONFROMTIMESP);
- Timer
- NSDate *datenow = [NSDate Date]; //Time now, you can output to see what the format is
- Nstimezone *zone = [Nstimezone systemtimezone];
- Nsinteger interval = [zone Secondsfromgmtfordate:datenow];
- NSDate *localedate = [Datenow datebyaddingtimeinterval:interval];
- NSLog (@"%@", localedate);
- NSString *timesp = [NSString stringwithformat:@"%lld", (long long) [Localedate timeIntervalSince1970]];
- NSLog (@"timesp:%@", TIMESP); //Timestamp value 1369189763711 1369218563 1369218614
- NSDate *CONFROMTIMESP = [nsdate dateWithTimeIntervalSince1970:1369189763711/1000];
- NSLog (@"1363948516 =%@", CONFROMTIMESP);
- //Instantiate a NSDateFormatter object
- //Judge yesterday morning time before the day of the hour stamp
- NSDateFormatter *dateformatter1 = [[[[NSDateFormatter alloc] init] autorelease];
- [DateFormatter1 setdateformat:@"Yyyy-mm-dd 00:00:00"];
- NSString *currentdatestr1 = [dateFormatter1 stringfromdate:[nsdate Date]];
- NSLog (@"wee Hours:%@", CURRENTDATESTR1);
- NSString *TIMESP1 = [NSString stringwithformat:@"%lld", (long long) [Localedate timeIntervalSince1970]];
- NSLog (@"Morning time stamp:%@", TIMESP1);
- //Yesterday morning time stamp
- NSString *timesp2 = [NSString stringwithformat:@"%lld", (long long) [Localedate timeintervalsince1970]- 24*60*60];
- NSLog (@"Yesterday morning Time stamp:%@", TIMESP2);
NSDate Timestamp and string conversion