Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i display current time on a label?

how can i display current time on a label iphone?

like image 302
iOS_User Avatar asked Dec 07 '22 03:12

iOS_User


1 Answers

Objective-C

NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd.MM.YY HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:currDate];

yourLabel.text=dateString

Swift 3.0

var currDate = Date()
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd.MM.YY HH:mm:ss"
var dateString = dateFormatter.string(fromDate: currDate)
yourLabel.text! = dateString
like image 51
Himanshu padia Avatar answered Dec 21 '22 06:12

Himanshu padia