It is worth noting that the% prefix is ββrequired for any string with a single character when using the DateTime.ToString(string) method, even if this string is not one of the built-in format string format templates; I ran into this problem while trying to get the current hour. For example, a code snippet:
DateTime.Now.ToString("h")
will throw a FormatException . Change above:
DateTime.Now.ToString("%h")
indicates the current hour.
I can only assume that the method looks at the length of the format string and decides whether it represents an embedded or custom format string.
source share