[Objective-C] Get current Date and Time

Get current and formatted time from your simulator or device!

[code lang=”java” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]- (NSString*) getDateTime {
     NSDateFormatter *formatter;
     NSString        *dateString;
 
     formatter = [[NSDateFormatter alloc] init];
     [formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
 
     dateString = [formatter stringFromDate:[NSDate date]];
     [formatter release];

     NSLog(@"Current data: %@", dateString);
     return dateString;
}[/code]

eof

Rif: albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.