I have a question regarding the symbol that separates days from hours in TimeSpan.ToString
output.
The standard TimeSpan
format strings produce different separator symbols:
- "c" produces a period (".") character
- "g" and "G" produce a colon (":") character
Example:
// Constant format
Console.WriteLine(TimeSpan.FromDays(42).ToString("c", CultureInfo.InvariantCulture));
// Output: 42.00:00:00 (period character between days and hours)
// General short format
Console.WriteLine(TimeSpan.FromDays(42).ToString("g", CultureInfo.InvariantCulture));
// Output: 42:0:00:00 (colon character between days and hours)
// General long format
Console.WriteLine(TimeSpan.FromDays(42).ToString("G", CultureInfo.InvariantCulture));
// Output: 42:00:00:00.0000000 (colon character between days and hours)
Does anybody know what's the logic behind it?
However TimeSpan.Parse
parses all of these string successfully.
TimeSpan
and sometimes you sayDateTime
, is this by mistake? – Immutable