Basic use of IOS nsdate dates

Source: Internet
Author: User

String zonestr timestamp #pragma mark timestamp turns into time

-(nsstring *) Timestampintotime: (nsstring *) zonestr{

//timestamp string converted to date string

Long long index = [zonestr longlongvalue];

nsdate *sinedate = [nsdate dateWithTimeIntervalSince1970: index/ ];

nsdateformatter *dateformatter = [[nsdateformatter alloc] init];

//yyyy mm month dd Day HH24 hours HH12 hours mm minutes ss seconds mmmm month

[dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss MMMM"];

//date turn into time

nsstring *datastring = [dateformatter stringfromdate: sinedate];

return datastring;

}


A string that #pragma mark time to turn into a timestamp

-(nsstring *) timestamp{

//Get the system time

nsdate *date = [nsdate date];

//time stamp

long secondtimezone = [date timeIntervalSince1970]*;

//timestamp turns into a string

nsstring *zonestr = [nsstring stringwithformat:@ "%@"@ (secondtimezone )];

return zonestr;

}


#pragma mark Format time

-(nsstring *) formattedtime{

//Get the system time

nsdate *date = [nsdate date];

//Time to format the system

nsdateformatter *dateformatter = [[nsdateformatter alloc] init];

//yyyy mm month dd Day HH24 hours HH12 hours mm minutes ss seconds mmmm month

[dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss MMMM"];

//date turn into time

nsstring *datastring = [dateformatter stringfromdate:d ate];

return datastring;

}


#pragma mark to format a string of time datastr for the specified time zone

-(nsstring *) Timezonetimeformat: (nsstring *) datastr{

nsdateformatter *dateformatter = [[nsdateformatter alloc] init];

[Dateformatter Setdateformat:@ "Yyyy-mm-dd hh:mm"];

nsdate *date = [dateformatter datefromstring:d atastr];

Dateformatter. TimeZone = [nstimezone timezonewithname:@ "Asia/shanghai"];

nsstring *strdate = [dateformatter stringfromdate:d ate];

return strdate;

}


Basic use of IOS nsdate dates

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.