iOS development--Get time

Source: Internet
Author: User

Get the current day of the month, the current time division seconds to obtain, weeks and weeks to obtain nsdate*date = [NSDate Date]; Nscalendar*calendar = [Nscalendar Currentcalendar]; Nsdatecomponents*comps; Year-day comps =[calendar components: (Nsyearcalendarunit | Nsmonthcalendarunit | Nsdaycalendarunit) fromdate:date]; Nsintegeryear = [Comps year]; Nsintegermonth = [Comps month]; Nsintegerday = [Comps day]; NSLog (@ "year:%d month:%d, day:%d", year, month, day); Current time division seconds to get comps =[calendar components: (Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit) fromdate:date]; Nsintegerhour = [Comps hour]; Nsintegerminute = [comps minute]; Nsintegersecond = [comps second]; NSLog (@ "hour:%d minute:%d second:%d", hour, minute, second); Weeks and days of the week get Comps =[calendar components: (Nsweekcalendarunit | Nsweekdaycalendarunit | Nsweekdayordinalcalendarunit) fromdate:date]; Nsinteger week = [Comps week]; Nsintegerweekday = [Comps weekday] in the first weeks of this year; Day of the week (note that Sunday is "1", Monday is "2”。。。。 ) nsintegerweekdayordinal = [Comps weekdayordinal]; The week ordinal of the month NSLog (@ "week:%d Weekday:%d weekday ordinal:%d", week, weekday, weekdayordinal);       Nsdateformatter*dateformatter = [[NSDateFormatter alloc]init];       if (dateswitch.on) [dateformattersetdateformat:@ "Dd-mmm-yyy,hh:mm:ss"];       else [dateformatter setdateformat:@ "Hh:mm:ss"];       Labeltime.text = [Dateformatter stringfromdate:[nsdatedate]];       Labeltime.font = [UIFontsystemFontOfSize:fontSlider.value]; [Dateformatter release];

  

Background timestamp converted to yyyy MM month DD Day

Const long long datetimelong =[value longlongvalue]/;

nsdate *datetime = [[nsdate alloc] initWithTimeIntervalSince1970:d Atetimelong];

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

[Formatter settimestyle:nsdateformatternostyle];

[Formatter setdatestyle:nsdateformattermediumstyle];

nslocale *formatterlocal = [[nslocale alloc] initwithlocaleidentifier:@ "en _us "];

[Formatter SetLocale: formatterlocal];

[Formatter Setdateformat:@ "yyyy MM month DD day "];

nsdate *new = [nsdate datewithtimeinterval:0 sincedate:d atetime];

nsstring *datestring = [Formatter stringfromdate: new];

iOS development--Get time

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.