Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the current time in a DateTimePicker

I am trying to set the current time to a DateTimePicker (with Format Time) like

this.myDateTimePicker.Value = DateTime.Now;

but when executing my code I am getting an exception

Object reference not set to an instance of an object    

What I am doing wrong?

Thanks.

like image 777
georgeliatsos Avatar asked Aug 02 '12 19:08

georgeliatsos


People also ask

How do I set the time on my datetime picker?

It Seems simple. $('#startdatetime-from'). datetimepicker({ language: 'en', format: 'yyyy-MM-dd hh:mm' });

How can I get current date in Datepicker?

On the All tab of the Property Sheet, make sure the Show Date Picker property is set to For dates. On the Data tab of the property sheet, type =Date() in the Default Value property for the field. Note: If you want to include the current time as well as the date, use the Now() function instead of Date().

How do I set default value in TimePicker?

Setting the Default Value To set the initial value that is rendered by the TimePicker, set the defaultValue property. This approach allows the component to display a value upon its initial render while remaining in an uncontrolled state.

What is a date time picker?

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.


1 Answers

You need to put that code after the InitializeComponent() call is made. There is no instance of myDateTimePicker until that point.

like image 146
code4life Avatar answered Sep 22 '22 03:09

code4life