Mode one: xxxx year-xx month-xx day xx: xx minutes: XX second format
-(Ibaction) Loginaction: (UIButton *) sender
{
NSDate *date = [NSDate Date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[Formatter Setdatestyle:nsdateformattermediumstyle];
[Formatter Settimestyle:nsdateformattershortstyle];
[Formatter setdateformat:@ "Yyyy-mm-dd Hh:mm:ss"];
NSString *datetime = [Formatter stringfromdate:date];
NSLog (@ "%@============ year-month-day time: minutes: Seconds =====================", DateTime);
}
Mode two: XXXX year-X month-X day XX: xx minutes: xx seconds format
-(Ibaction) Loginaction: (UIButton *) sender{
NSDate *now = [NSDate Date];
NSLog (@ "Now date was:%@", now);
Nscalendar *calendar = [Nscalendar Currentcalendar];
Nsuinteger unitflags = Nsyearcalendarunit | Nsmonthcalendarunit | Nsdaycalendarunit | Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit;
nsdatecomponents *datecomponent = [Calendar components:unitflags Fromdate:now];
int year = (int.) [Datecomponent year];
int month = (int) [Datecomponent month];
int day = (int.) [Datecomponent Day];
int hour = (int) [Datecomponent hour];
int minute = (int) [Datecomponent minute];
int second = (int) [datecomponent second];
Nsinteger year = [datecomponent year];
Nsinteger month = [datecomponent month];
Nsinteger day = [Datecomponent day];
Nsinteger hour = [Datecomponent hour];
Nsinteger minute = [datecomponent minute];
Nsinteger second = [datecomponent second];
NSLog (@ "Year was:%ld", (long) year);
NSLog (@ "Month is:%ld", (long) month);
NSLog (@ "Day was:%ld", (long) day);
NSLog (@ "Hour is:%ld", (long) hour);
NSLog (@ "Minute is:%ld", (long) minute);
NSLog (@ "Second is:%ld", (long) second);
Conversion and splicing of strings
NSString *yearstr=[nsstring stringwithformat:@ "%ld-", (long) year];
NSString *monthstr=[nsstring stringwithformat:@ "%ld-", (long) month];
NSString *daystr=[nsstring stringwithformat:@ "%ld", (long) day];
NSString *hourstr=[nsstring stringwithformat:@ "%ld:", (long) hour];
NSString *minutestr=[nsstring stringwithformat:@ "%ld:", (long) minute];
NSString *secondstr=[nsstring stringwithformat:@ "%ld", (long) second];
String Start stitching
NSString *allstr=[yearstr STRINGBYAPPENDINGSTRING:MONTHSTR];
NSString *allstr1=[allstr STRINGBYAPPENDINGSTRING:DAYSTR];
NSString *allstr2=[allstr1 STRINGBYAPPENDINGSTRING:HOURSTR];
NSString *ALLSTR3=[ALLSTR2 STRINGBYAPPENDINGSTRING:MINUTESTR];
NSString *DATETIME=[ALLSTR3 STRINGBYAPPENDINGSTRING:SECONDSTR];
NSLog (@ "Last month days and minutes and seconds stitching results =====%@", DateTime);
}
Gets the current time---month, minutes, seconds------IOS