Results 1 to 4 of 4

Thread: Format TimeSpan

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Format TimeSpan

    I'm thinking this should be easy, but I can't figure out how to format a TimeSpan object the way I'd like it displayed.

    I'd like to display as hh:mm:ss - that is, without the milliseconds. Can anyone help me out?

    Thanks,
    Mike

  2. #2

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    FWIW, this is the simplest I could come up with, this is in C#
    PHP Code:
    timeSpan.ToString().Substring(0timeSpan.ToString().LastIndexOf(".")); 

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this?
    VB Code:
    1. dim tm as timespan
    2. . . .
    3. string.format("{0}:{1}:{2}",tm.hours,tm.minutes,tm.seconds)
    if not, sorry.

  4. #4

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    That kind of works, but I (or my users I should say) want it formatted with leading zeros, if need be. Also (this would be easy to add to your code), number of days should be part of the result. This is why I used LastIndexOf, instead of IndexOf.

    Thanks,
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width