简体   繁体   中英

How to get string value from date time picker specific date setting

I'm trying to set date with date time picker this way year/month/day . I don't want get current time:

label1.Text = dateTimePicker1.Value.ToString("yyyy-MM-dd");

I'm trying to set the range between given specific dates, for example from 1970/1/2 to 1980/4/2

so the only thing I'm trying is to get the string value as it is "1970/1/2" or integer. It does not matter if it is formatted separately with slashes or with dots (1970.1.2). It must be equal to settings with date time picker as it is given by the user in GUI, to process this range.

You have to set the format of your datetime picker. This can be done using the .Format property

public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}

More info can be found here: https://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.format(v=vs.110).aspx

You can set a custom format:

dateTimePicker.CustomFormat = "yyyy-MM-dd";
dateTimePicker.Format = DateTimePickerFormat.Custom;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM