first create a formatted object
nsdateformatter *dateformatter = [[nsdateformatter alloc] init];
[Dateformatter Setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];
// then create a Date object
nsdate *date1 = [dateformatter datefromstring:@ "2014-12-20 00:00:00"];
nsdate *date = [nsdate date];
// Calculate time interval (units in seconds)
nstimeinterval Time = [date1 timeintervalsincedate:d ate];
// count days, hours, minutes, seconds
int days = ((int) time)/(3600*);
int hours = ((int) time)% (3600*)/3600;
int minutes = ((int) time)% (3600*)%3600/;
int seconds = ((int) time)% (3600*)%3600;
nsstring *datecontent = [[nsstring alloc] initwithformat:@ "Some day of a certain month in a certain year %i days %i hours %i minutes %i seconds ", days,hours,minutes,seconds];
//(%i can automatically convert input to decimal , and %d does not convert)
// Assign value display
UILabel *timelab = (UILabel *) [self. View viewwithtag:666666];
Timelab. text = datecontent;
NSLog(@ "%@", datecontent);
Report:
Draw Heart 1:
#include <stdio.h>
int main () {
for (float y=1.5f;y>-1.5f;y-=0.1f) {
for (float x=-1.5f;x<1.5f;x+=0.05f) {
float a= x*x+y*y-1;
Putchar (a*a*a-x*x*y*y*y<=0.0f? ') *‘:‘‘);}
}
}
Draw Heart 2:
IOS-Date Time difference (a certain day of the month of the year ...) )