Reputation: 573
I am new to OSX App development. In one of the sample menubar Apps I did, I used an NSDatePicker
object. But it is not displaying the current date. How can i display the current date using an NSDatePicker
object.
Upvotes: 2
Views: 5324
Reputation: 2379
set current system time to Datepicker
@IBOutlet weak var txtStartTime: NSDatePicker!
swift
let now = Date()
txtStartTime.dateValue = now
Upvotes: 1
Reputation: 2368
You can set date to date picker in Swift 3.2
like,
self.datePicker.dateValue = NSDate() as Date
Upvotes: 0
Reputation: 4675
As of OSX 10.4, the way to do this is
NSDate *currentDate = [NSDate date];
[datePicker setDateValue:currentDate];
Upvotes: 0
Reputation: 7388
Did you try
NSdate *currentDate = [NSDate date];
datePicker.date = currentDate;
??
this is the same as
NSdate *currentDate = [NSDate date];
[datePicker setDate:currentDate]
The main difference is that if currentDate
is not equal to nil in your code, the datePicker's date does not get set!!
Upvotes: 4