Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Time format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Time format

    I am trying to get just the time portion of a ToTime[1] call.

    I have been at it all afternoon.

    I want it to look like "01:03" but I get 2 difficulties.

    1.The only way I have been half successful is to use stringbuilder and then chop up the above into two segments. Is there an easier way?

    2. 0103 comes out as 10:03

    edit - the ToTime seems to throw away the zeros? eg 00:51 becomes 51?

    Code:
    	string mystr = (ToTime(Time[1])).ToString();
    StringBuilder leftbit  = new StringBuilder();
    leftbit.Append(mystr.Substring(0,2)+":");
    leftbit.Append(mystr.Substring(2,2));
    Print("My time" + leftbit.ToString());
    Last edited by Mindset; 01-29-2009, 12:41 PM.

    #2
    Without having tested, I think it is something like: Time[1].ToString("t").

    Comment


      #3
      That is just so frustrating - I looked through the format protocols. Guess I must have just missed it.
      thanks Ralph.
      Last edited by Mindset; 01-29-2009, 02:23 PM.

      Comment


        #4
        ToTime() formats the time into an integer.

        00:51 will show up as 51.
        11:51 will show up as 1151.

        Building your own string would be the way I would proceed. You can also access the hours and minutes directly from the DateTime object.

        Time[0].Hour
        Time[0].Minute
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          format

          Would it be proper to use Time[0].Hour + ":" + Time[0].Minute or
          build it with string builder?
          I seem to remember reading that concatenation is relatively resource / memory intensive.

          Edit - actually you can do it all in Time[1].ToString("t") which seems the neatest way to achieve this. No stringbuilder required.
          Last edited by Mindset; 02-02-2009, 04:25 AM.

          Comment


            #6
            Glad you got it resolved.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Agree with your conclusion, Mindset. Long time ago I tried to outperform the standard-C string-functions by self written code with pointers. But I never reached the same performance. Since this time I first look what functions are offered by a language before coding my own stuff.

              Regards
              Ralph

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by adeelshahzad, Today, 03:54 AM
              5 responses
              30 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by stafe, 04-15-2024, 08:34 PM
              7 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              17 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Working...
              X