如何转换日起在C#MM / DD / YY格式 [英] How to Convert date into MM/DD/YY format in C#

查看:139
本文介绍了如何转换日起在C#MM / DD / YY格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Asp.net网页我需要显示当天的日期到文本框之一,所以在我的窗体加载我写了下面的代码



  textbox1.text = System.DateTime.Today.ToShortDateString(); 

这行让我喜欢约会,但1/7/09我要像日期1月7日/ 09,反正是有,我可以在C#中CONVER此日期为MM / DD / YY格式?


解决方案

  DateTime.Today.ToString(MM / DD / YY)

看对于定制的日期和时间格式字符串文档获取更多信息。



(呵呵,我希望这个程序是不是发往其他文化。这种格式可以真正迷惑了很多人......我从来没有了解整个月/日/年的事情,说实话,它只是似乎不可思议去中/低/高,在这样的规模上。)


In My Asp.net webpage I need to display today's date into one of the textbox , so in my form load I wrote the following code

textbox1.text = System.DateTime.Today.ToShortDateString();

this line is giving me date like 1/7/09 but I want date like 01/07/09 , Is there anyway I can conver this date into mm/dd/yy format in C#?

解决方案

 DateTime.Today.ToString("MM/dd/yy")

Look at the docs for custom date and time format strings for more info.

(Oh, and I hope this app isn't destined for other cultures. That format could really confuse a lot of people... I've never understood the whole month/day/year thing, to be honest. It just seems weird to go "middle/low/high" in terms of scale like that.)

这篇关于如何转换日起在C#MM / DD / YY格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆