nbs
nbs

Reputation: 573

How to set current date on NSDatePicker object in osx

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

Answers (4)

Darshan
Darshan

Reputation: 2379

set current system time to Datepicker

@IBOutlet weak var txtStartTime: NSDatePicker!      

swift

let now = Date()
txtStartTime.dateValue = now

Upvotes: 1

iParesh
iParesh

Reputation: 2368

You can set date to date picker in Swift 3.2like,

self.datePicker.dateValue = NSDate() as Date

Upvotes: 0

Kevin_TA
Kevin_TA

Reputation: 4675

As of OSX 10.4, the way to do this is

NSDate *currentDate = [NSDate date];
[datePicker setDateValue:currentDate];

Upvotes: 0

DD_
DD_

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

Related Questions