For the time that is frequently used in projects, data operations in the form of timestamps can bring great convenience. The following describes how to generate and convert timestamps in the form of demo.
Declare a time-type variable:
// Obtain the current time // The first method below does not advocate // nsdate * now1 = [[nsdate alloc] initwithtimeintervalsincenow: 8*60*60]; nsdate * today = [nsdate date]; nstimezone * zone = [nstimezone systemtimezone]; nsinteger interval = [zone secondsfromgmtfordate: Today]; nsdate * localedate = [Today interval: interval]; nslog (@ "% @", localedate); // converts the time to the timestamp nsstring * timesp = [nsstring stringwithformat: @ "% lD", (long) [localedate timeintervalsince1970]; nslog (@ "timesp: % @", timesp );
Time stamp to nsdate)
// Convert the timestamp to date nsdate * currenttime = [nsdate datewithtimeintervalsince1970: [timesp intvalue]; nslog (@ "currenttime: % @", currenttime );