none
TimeSpan Custom Format RRS feed

  • Question

  • Hi,

    I had a problem with timespan custom format.I had paste my code below.In my code the second line through an error.The error message is

    overload failed because no accessible 'ToString' accepts this number of arguments.

       Dim TimeSp As TimeSpan = Now.Subtract(Now.Add(TimeSpan.FromMilliseconds(CountdownClock)))


       Dim TimeLeft As String = TimeSp.ToString("mmssf")  -> This line through above error.

      


    Monday, February 4, 2019 6:57 AM

Answers

  • Go to Project Properties, and change the "Target framework" to 4 or above, if possible.

    Also check if it is correct to assign a string to TimeSpan in the shown code.

    Tuesday, February 5, 2019 6:47 AM

All replies

  • According to documentation, it should work (in a Console or Forms application, for example). Do these lines appear together in your program, or maybe you have some other variable called “TimeSp”.

    • Edited by Viorel_MVP Monday, February 4, 2019 9:40 AM
    Monday, February 4, 2019 9:39 AM
  • Hi,

    I had a problem with timespan custom format.I had paste my code below.In my code the second line through an error.The error message is

    overload failed because no accessible 'ToString' accepts this number of arguments.

       Dim TimeSp As TimeSpan = Now.Subtract(Now.Add(TimeSpan.FromMilliseconds(CountdownClock)))


       Dim TimeLeft As String = TimeSp.ToString("mmssf")  -> This line through above error.

      


    Hi

    I can not get the exception you mention. Are you certsin that you are showing the same code that you are having the exception from?

    Here is the code I tested with. I used 3 different formats to test with and all worked as expected.

        Dim TimeSp As TimeSpan = Now.Subtract(Now.Add(TimeSpan.FromMilliseconds(1234567)))
        ' TimeSp = -00:20:34:567000
    
        Dim TimeLeft1 As String = TimeSp.ToString("mmssf")
        ' TimeLeft1 = "20345"
    
        Dim TimeLeft2 As String = TimeSp.ToString("mm\m\ ss\s\ f\m\s")
        ' TimeLeft2 = "20m 34s 5ms"
    
        Dim TimeLeft3 As String = TimeSp.ToString("mm\m\ ss\s\ fff\m\s")
        ' TimeLeft3 = "20m 34s 567ms"


    Regards Les, Livingston, Scotland

    Monday, February 4, 2019 10:11 AM
  • Hi,

    I had a problem with timespan custom format.I had paste my code below.In my code the second line through an error.The error message is

    overload failed because no accessible 'ToString' accepts this number of arguments.

       Dim TimeSp As TimeSpan = Now.Subtract(Now.Add(TimeSpan.FromMilliseconds(CountdownClock)))


       Dim TimeLeft As String = TimeSp.ToString("mmssf")  -> This line through above error.

      


    Put a breakpoint on the line in error.  What is in TimeSp?  I could not reproduce the error either, but I don't know what was in CountdownClock.



    Search Documentation

    SerialPort Info

    Multics - An OS ahead of its time.

     "Those who use Application.DoEvents have no idea what it does

        and those who know what it does never use it."    former MSDN User JohnWein

    Monday, February 4, 2019 3:55 PM
  • Hi Muraleedharan.K,

    Please check the type named TimeSpan, is it a custom class or library in .net framework. 

    If the issue still exists, could you please share a simple complete sample to reproduce the issue via OneDrive.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 5, 2019 5:47 AM
    Moderator
  • Sir,

    I am using visual studio 2008.It always throws above mentioned problem.Is there any problem with visual studio 2008 version.Check my attached screenshot.see the error message in my screenshot

    Tuesday, February 5, 2019 6:39 AM
  • Go to Project Properties, and change the "Target framework" to 4 or above, if possible.

    Also check if it is correct to assign a string to TimeSpan in the shown code.

    Tuesday, February 5, 2019 6:47 AM