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