我在WPF中遇到了datepicke的问题 [英] I have a problem with datepicke in WPF
问题描述
首先,我插入一个控件datepicker的日期,然后当我想修改一些数据时,我不想更改日期,它会自动更改为默认值01/01/1990 00:00:00 。
问题是我不想显示仅限时间日期。
First, I insert a date with control "datepicker", then when I want to modify some data I dont want to change the date it will change automatically to the default value which is 01/01/1990 00:00:00.
Problem is that I don't want to display the time only date.
推荐答案
1 。
1.
CultureInfo newCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.DateSeparator = "/";
Thread.CurrentThread.CurrentCulture = newCulture;
2.
2.
DateTime myDate = new DateTime();
string us = myDate.ToString(new CultureInfo("en-US"));
因为你是新手,所以你首先需要了解DateTime对象是什么以及日期时间选择器对象将返回给你,它是一个字符串而不是DateTime。
你需要将它转换为DateTime对象然后你可以在它上面做DateTime数学。
| 我第一次使用控件datepicker插入日期,
您需要获取日期时间选择器对象,并将有效字符串传递给它或从提供的UI中选择。
| 第二次我要修改一些数据而我不想将它自动更改的日期更改为默认值01/01/1990 00:00:00
要自动更改它,您只需创建一个新实例,它将返回到DateTime的Min值,就像这样
Since you're a newbie you first need to understand what a DateTime object is and what a date time picker object would return to you, it is a string not a DateTime.
You need to convert it to the DateTime object and then you can do the DateTime maths on it.
| in the first time I insert a date with control "datepicker",
for that you need to get a date time picker object, and pass a valid string to it or select from the UI provided.
| in the second time when i want to modify some data and i dont want to change the date it will change automatically to the default value which is 01/01/1990 00:00:00
To change it automatically, you can simply just create a new instance, and it will go back to the Min value of the DateTime, like this
DateTime dateTime = new DateTime(); // there you go!
完成后,您可以使用内置函数获取Date部分,例如
Once done, you can get the Date part using a built-in function like
MessageBox.Show(dateTime.ToLongDateString());
它只会显示dateTime对象的日期部分。
我写了一篇关于DateTime对象的文章以及如何在WPF中使用它,了解.NET Framework中的DateTime结构(使用C#) [ ^ ]随时阅读并询问是否需要帮助! :-)祝你好运。
It will show you with the date part of the dateTime object only.
I have written an article about the DateTime object and how you can use it in WPF, Understanding DateTime struct in .NET Framework (using C#)[^] feel free to read it and ask question if help needed! :-) Good luck.
这篇关于我在WPF中遇到了datepicke的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!