Objective-c conversion and time of timestamp conversions

Source: Internet
Author: User

What is a timestamp?

time Stamp ( timestamp ), which is typically a sequence of characters. Uniquely identifies a moment in time. Digital Timestamp technology is A variant application of digital signature technology.

thinking: Simply speaking is based on the file hash encryption generated by the digest and time generated time certificate, its value is from 1970 years 1 Month 1 Day 8 The total number of milliseconds to point to today's time

in Objective - C How do I convert timestamps to nsdate?

Nsstring*[email protected] "1283376197";

Nstimeintervaltime=[str Doublevalue];

Nsdate*detaildate=[nsdate Datewithtimeintervalsince1970:time];

NSLog (@ "date:%@", [detaildatedescription]);

think: Use this function. The double value of the time stamp is passed to get the nsdate time .

How do I convert the current time to a timestamp?

nsdate *datenow =[nsdate Date]; // Today's Time , you can output to see what the format is

Nstimezone *zone = [nstimezone systemtimezone];

nsinteger interval = [zone secondsfromgmtfordate:d Atenow];

nsdate *localedate = [Datenow datebyaddingtimeinterval: interval];

NSString *TIMESP = [nsstring stringwithformat: @ "%d", (long) [Localedate timeIntervalSince1970]];

NSLog (@ "timesp:%@", TIMESP); // value of time stamp

think: The interval of the standard time based on the current time and the system's time zone, and then the time after validation lo caledate , and finally [localedate timeIntervalSince1970] get the time after the validation and 1970 the difference between the years and the time stamp



How to format output nsdate?

Nsdateformatter*formatter = [[NSDateFormatter alloc]init];

[formattersetdateformat:@ "yyyy mm month DD Day"];

NSDate *date =[formatter Stringfromdate:detaildate];

NSLog (@ "date:%@", date);

think: Create a NSDateFormatter class, and then pass a nsdate on it.

"Yyyymmddhhmmss" represents the seconds of the month and day

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Objective-c conversion and time of timestamp conversions

Related Article

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.