How to control appearance of ':' in time zone offset when parsing/formatting Datetime

前端 未结 4 1509
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 17:40

I\'m working with a protocol that may optionally include a time zone offset when specifying datetime information. My code is written in C# and we are using the 4.0 .NET run

4条回答
  •  感动是毒
    2020-12-06 17:53

    Doesn't look like there is anything built-in (you can use zz, but that leaves out the minutes).

    You can roll your own by instantiating a DateTimeFormatInfo, setting TimeSeparator to string.Empty and using that as the IFormatProvider when calling DateTime.ToString (and make the call explicit, if it is not already).

    But frankly, using Replace to remove the unwanted : from the default return value is so much easier.

提交回复
热议问题