[dba-VB] FYI: TimeStamp formatting issue for VS2010/.NET 4.0

Gustav Brock Gustav at cactus.dk
Mon Jun 6 06:07:05 CDT 2011


Hi Stuart

Well, yes for the format string, but "any" separator is not (can not) be used to separate the value and the format string; it has to be a colon:

string s = string.Format("{0:hh\\:mm\\:ss}", ts);

/gustav


>>> "Stuart McLachlan" <stuart at lexacorp.com.pg> 06-06-2011 11:57 >>>
Not just the colon, any separator:

<quote>
The custom TimeSpan format specifiers do not include placeholder separator symbols, such 
as the symbols that separate days from hours, hours from minutes, or seconds from 
fractional seconds. Instead, these symbols must be included in the custom format string as 
string literals. For example, "dd\.hh\:mm" defines a period (.) as the separator between days 
and hours, and a colon (:) as the separator between hours and minutes. 
</quote>

-- 
Stuart
On 6 Jun 2011 at 11:41, Gustav Brock wrote:

> Hi Shamil
> 
> So what you try to tell ... is that a colon on its own now is reserved
> for the use as the separator between the value and the format string?
> 
> /gustav
> 
> 
> >>> shamil at smsconsulting.spb.ru 05-06-2011 22:12 >>>
> Hi All --
> 
> FYI: I have got used to format TimeStamp values this simple way (for
> TimeStamp values less than a day):
> 
> TimeStamp ts = new TimeStamp(10,11,12);
> string s = string.Format("{0:hh:mm:ss}", ts);
> System.Console.WriteLine(s);
> 
> and it worked well for VS2008/.NET 3.5 but when my project was
> converted to VS2010SP1/.NET 4.0 I have got runtime error...
> 
> Proper TimeStamp formatting for my case should be {0:hh\\:mm\\:ss} :
> 
> TimeStamp ts = new TimeStamp(10,11,12);
> string s = string.Format("{0:hh\\:mm\\:ss}", ts);
> System.Console.WriteLine(s);
> 
> Source: http://msdn.microsoft.com/en-us/library/ee372287.aspx 
> 
> Thank you.
> 
> --
> Shamil





More information about the dba-VB mailing list