Issues with IOS timestamps

Source: Internet
Author: User

-(NSString *) timewithtimeintervalstring: (NSString *) timestring{//format Timensdateformatter* formatter =[[NSDateFormatter alloc] init]; Formatter.timezone= [Nstimezone timezonewithname:@"Shanghai"];    [Formatter Setdatestyle:nsdateformattermediumstyle];    [Formatter Settimestyle:nsdateformattershortstyle]; [Formatter Setdateformat:@"yyyy mm month DD Day hh:mm"]; //millisecond value converted to secondsnsdate* date = [NSDate datewithtimeintervalsince1970:[timestring doublevalue]/1000.0]; NSString* DateString =[Formatter stringfromdate:date]; returndatestring;} Time conversion to timestamp//Current Timensdate* date = [NSDate Datewithtimeintervalsincenow:0]; Nstimeinterval a=[date timeintervalsince1970]* +;//*1000 is accurate to milliseconds, no multiplication is accurate to secondsNSString *timestring = [NSString stringWithFormat:@"%.0f", a];//convert to character typemethod of returning month and day by comparing time with current time- (void) Getbabydetailage: (NSString *) date{//Get Date ObjectNSDateFormatter *formatter_ =[[NSDateFormatter alloc] init]; Formatter_.dateformat=@"YYYY-MM-DD HH:mm:ss"; NSDate*createdate =[Formatter_ datefromstring:date]; Nscalendar*gregorian =[[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian]; Nsuinteger Unitflags= Nscalendarunitday | Nscalendarunitmonth |nscalendarunityear; Nsdatecomponents*components = [Gregorian components:unitflags fromdate:createdate todate:[nsdate Date] Options:0 ]; Nsinteger years=[Components of year ]; Nsinteger months=[Components Month]; Nsinteger Days=[Components day];}

Issues with IOS timestamps

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.