Nsdate and timestamp

Source: Internet
Author: User
Tags timestamp to date

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 );



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.