Time converted to Unix Timestamp

Source: Internet
Author: User
@ Interface stamptransformmer + (unsigned long) getstamp :( nsstring *) input; @ end @ implementation stamptransformmer + (unsigned long) getstamp :( nsstring *) input {const char * timestr; unsigned long ret; unsigned long lyearcount; unsigned long year, month, day, hour, Min, SEC; timestr = [input utf8string]; sscanf (timestr, "% u-% u: % u", & year, & month, & day, & hour, & min, & Sec ); unsigned long daysum [] = {0, 31, 59, 90,120,151,181,212,243,273,304,334}; lyearcount = (year-1)/4-(year-1)/100 + (year-1)/400) -(1969/4-1969/100 + 1969/400); ret = (year-1970) * 365*24*3600 + lyearcount * 24*3600; RET + = daysum [month-1] * 24*3600; If (month> 2 & (Year % 4 = 0 & year % 100! = 0) | year % 400 = 0) RET + = 24*3600; RET + = (day-1) * 24*3600 + hour * 3600 + min * 60 + sec; return ret;} @ endint main () {NSAID utoreleasepool * pool; pool = [[NSAID utoreleasepool alloc] init]; nslog (@ "% u", [stamptransformmer getstamp: @ "17:40:50"]); [pool release]; return 0 ;}

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.