How to change date format from DD/MM/YYYY or MM/DD/YYYY to YYYY-MM-DD?

后端 未结 4 1410

i need to change the format of my date string using C#

from : \"06/16/2010\"or \"16/06/2010\"

to : \"2010-06-16\"

can you please help me achieve this

4条回答
  •  清歌不尽
    2020-11-30 12:59

    We can do something like this

    DateTime date_temp_from = DateTime.Parse(from.Value); //from.value" is input by user (dd/MM/yyyy)
    DateTime date_temp_to = DateTime.Parse(to.Value); //to.value" is input by user (dd/MM/yyyy)
    
    string date_from = date_temp_from.ToString("yyyy/MM/dd HH:mm");
    string date_to = date_temp_to.ToString("yyyy/MM/dd HH:mm");
    

    Thank you

提交回复
热议问题