Date.parse(2/4/2011 9:34:48 AM)

后端 未结 3 621
北荒
北荒 2021-01-24 05:30

my input will be from a variable (Ticket.CreationDate) and will look like

2/4/2011 9:34:48 AM (it will vary of course)

Ideally I could pass in the variable as-i

3条回答
  •  轮回少年
    2021-01-24 05:58

    Create a function which takes date and in-format string and out-format string as parameter

    string FormatDate(string date, string informat,string outformat)
    {
        var culture = CultureInfo.CreateSpecificCulture("en-US");
        return DateTime.ParseExact(date, informat, culture).ToString(outformat);
    }
    
    FormatDate("2/4/2011 9:34:48 AM","M/d/yyyy H:m:s tt","H:m:s")               //9:34:48
    

    You can get different format string from here

提交回复
热议问题