Convert DateTime Format in C#

前端 未结 4 1628
攒了一身酷
攒了一身酷 2021-01-25 03:03

How can I convert this datetime format from a webservice. The datetime value is: \"timestamp\": \"2014-04-18T14:45:00+02:00\" I wan\'t to convert it to: dd.mm.YYYY hh.mm.ss

4条回答
  •  萌比男神i
    2021-01-25 03:26

    With a regex you can do the following:

    string resultString = null;
    try {
        resultString = Regex.Replace(subjectString, @"(\d{4})-(\d{2})-(\d{2})\w{1}(\d{2}):(\d{2}):(\d{2})\+\d{2}:\d{2}", "$3.$2.$1 $4.$5.$6", RegexOptions.IgnoreCase);
    } catch (ArgumentException ex) {
        // Syntax error in the regular expression
    }
    

    //18.04.2014 14.45.00

提交回复
热议问题