How to Convert date into MM/DD/YY format in C#

后端 未结 5 1321
自闭症患者
自闭症患者 2020-12-05 07:19

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.DateTi         


        
5条回答
  •  执笔经年
    2020-12-05 07:34

    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.)

    Others cultures really are a problem. For example, that code in portugues returns someting like 01-01-01 instead of 01/01/01. I also don't undestand why...

    To resolve that problem i do someting like this:

            IFormatProvider yyyymmddFormat = new System.Globalization.CultureInfo(String.Empty, false);
            return date.ToString("MM/dd/yy", yyyymmddFormat);
    

提交回复
热议问题