|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Formatting timespan objectsI want to report a timespan value in a textbox on a form and thought I
might be able to do eg: txtbox.text=format(timespan,"hh:mm:ss") but this gives an invalid cast. Is there is any short way of achieving this or do I need to extract and assemble each time element separately? Thanks JGD "John Dann" <n***@prodata.co.uk> schrieb: You may want to use 'String.Format' to concatenate the property values:>I want to report a timespan value in a textbox on a form and thought I > might be able to do eg: > > txtbox.text=format(timespan,"hh:mm:ss") > > but this gives an invalid cast. Is there is any short way of achieving > this or do I need to extract and assemble each time element > separately? \\\ MsgBox( _ String.Format( _ "{0:00}:{1:00}:{2:00}", _ ts.Hours, _ ts.Minutes, _ ts.Seconds _ ) _ ) /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Hi,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemTimeSpanClassToStringTopic.asp Ken --------------- "John Dann" <n***@prodata.co.uk> wrote in message I want to report a timespan value in a textbox on a form and thought Inews:vo9i4158kqhhecghda9mf00b25tp69caat@4ax.com... might be able to do eg: txtbox.text=format(timespan,"hh:mm:ss") but this gives an invalid cast. Is there is any short way of achieving this or do I need to extract and assemble each time element separately? Thanks JGD John,
In addition to the other comments. The "easiest" way to format a TimeSpan is to use the TimeSpan.ToString method, which will return the results in the format: [-][d.]hh:mm:ss[.ff] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemTimeSpanClassToStringTopic.asp Dim ts As TimeSpan txtbox.text= ts.ToString() Remember the ToString method of "formattable" objects in .NET is normally overridden to provide formatting for that object. If you don't want the fractional seconds or days on the formatted string, I normally convert the TimeSpan to a DateTime & then use custom DateTime formatting. Note TimeSpan itself only supports a fixed format, I will convert a TimeSpan into a DateTime if I need custom formatting. Dim ts As TimeSpan Dim dt As DateTime = DateTime.MinValue.Add(ts) Dim s As String s = ts.ToString() ' default TimeSpan formatting s = dt.ToString("H:mm:ss") ' custom DateTime formatting For details on custom datetime formats see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondatetimeformatstrings.asp For information on formatting in .NET in general see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformattingtypes.asp Hope this helps Jay Show quoteHide quote "John Dann" <n***@prodata.co.uk> wrote in message news:vo9i4158kqhhecghda9mf00b25tp69caat@4ax.com... >I want to report a timespan value in a textbox on a form and thought I > might be able to do eg: > > txtbox.text=format(timespan,"hh:mm:ss") > > but this gives an invalid cast. Is there is any short way of achieving > this or do I need to extract and assemble each time element > separately? > > Thanks > JGD
SqlDateTime.MinValue, SqlDateTime.MaxValue: WATCH OUT!
Excel ADO question Using a variable to specify the name of a control Datalist/datatable sorting Cannot Get MenuItem's name[Notsolved] how to use CurrentRowIndex for datagrid control ? memory stream XML and unicode problem Writing E-Mail Notfications VB.NET with ADO.NET compilation error. How do I run one project? |
|||||||||||||||||||||||