如何使用C#将日期从DD / MM / YYYY更改为YYYY

编程入门 行业动态 更新时间:2024-10-25 03:23:44
本文介绍了如何使用C#将日期从DD / MM / YYYY更改为YYYY-MM-DD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 DatePicker 选择日期。所以选择日期后,我应该通过 MessageBox 显示它。我可以显示它,但它是格式 DD / MM / YYYY 。

I am using DatePicker to select the Date. So after selecting the date, I should display it through a MessageBox. I can able to display it but it is in the format DD/MM/YYYY.

以 YYYY-MM-DD 的格式显示它。所以请任何人可以帮助我做的需要。 现在我使用代码显示日期:

And I want to display it in the format YYYY-MM-DD. So please can anyone help me to do the needful. Now I am displaying the date by using the code:

string date1 = datepicker.ValueString; MessageBox.Show(date1);

但我可以显示当前日期格式,并根据需要使用代码显示:

But I can display the current date format and display it as required by using code:

string format = "yyyy-MM-dd"; string f = DateTime.Now.ToString(format);

因此,请帮助我使用 DatePicker 。

推荐答案

我使用代码

<toolkit:DatePicker Name="datepicker" BorderBrush="Transparent" BorderThickness="0" Value="" Background="Transparent" TabNavigation="Cycle" Template="{StaticResource DatePickerControlTemplate1}"/>

在CS档案中,我加入了

and in CS file, I added

string format = "yyyy-MM-dd"; string date1 = datepicker.ValueString; DateTime datevalue = DateTime.Parse(date1); string d = datevalue.ToString(format); MessageBox.Show(d);

最后我得到了所需的输出和DatePicker的方式,我们必须安装WPtoolkit包

and Lastly I got the required output and By the way for DatePicker we have to install WPtoolkit Package

更多推荐

如何使用C#将日期从DD / MM / YYYY更改为YYYY

本文发布于:2023-10-28 18:36:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   日期   DD   MM   YYYY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!