473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

not displaying the fractional part of a timespan

Bob

Greetings All,

Is there a simple way of suppressing the fractional part of a timespan

At the moment I use one time span to populate another minus the fractional
part .. this is a bit clunky.

I'd love to inherit it an overload the ToString() method .. but I think its
a sealed class or some such in any case I had no joy there.

regards Sam
Aug 14 '07 #1
2 2004
On Aug 14, 9:08 am, Bob <nospam...@nospam.com.auwrote:
Is there a simple way of suppressing the fractional part of a timespan
Which fractional part? Fractions of a day, fractions of an hour,
fractions of a minute, fractions of a second?
At the moment I use one time span to populate another minus the fractional
part .. this is a bit clunky.
Just put that in a utility method somewhere and it should be fine.
Once you're using C# 3 you can use extension methods to make it *look*
like it's part of the DateTime type :)

Jon

Aug 14 '07 #2
Bob wrote:
>
Greetings All,

Is there a simple way of suppressing the fractional part of a timespan

At the moment I use one time span to populate another minus the
fractional part .. this is a bit clunky.
There's no _good_ way to do it AFAIK. But what I have done is to use
the TimeSpan to create a DateTime instance, and then take advantage of
the string formatting that you can use for DateTime.

For example:

TimeSpan ts = ...;
string strTime = (new DateTime() + ts).ToString("h:mm:ss");

I think it's a little silly that the same formatting that can be applied
to DateTime doesn't work for TimeSpan, but it's not hard to trick .NET
into doing it anyway. :)

Pete
Aug 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Søndergaard | last post by:
I Pascal there are a function for retriving the fractional part of a real number (Frac), I can't find any in the dotnet framework. The function needs to remove the integer part and keep only the...
3
by: Dragon | last post by:
Helo, There're so many methods for rounding in .NET, but I can't find any that will just drop fractional part of a number, e.g: -3.9 => -3. I tried: CInt(-3.9) Int(-3.9) Math.Round(-3.9)
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
2
by: djzbor | last post by:
Any who can help!! let i have a number 16.0230045 i want to count the fractional part of this number means i want to get the number of digits of the fractional part of this number and store each...
4
by: Bob | last post by:
Hi All, Was wondering if in C# there is an elegant way of displaying and or calculating fractions. The case: we have an app that measures/slices dices etc and all our internal measures and...
10
by: schaefer.mp | last post by:
Does anyone know of an approximation to raising a negative base to a fractional exponent? For example, (-3)^-4.11111 since this cannot be computed without using imaginary numbers. Any help is...
12
by: bsabiston | last post by:
Hi, I'm trying to get the fractional part of a floating point number. I've tried fmod() and modf(), and while both do work, they also occasionally return 1.0 for the fractional part of the number...
0
by: Chris Rebert | last post by:
On Wed, Nov 19, 2008 at 10:01 PM, srinivasan srinivas <sri_annauni@yahoo.co.inwrote: Since you really care about significant figures here, have you considered using decimal rather than float as,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.