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 TraderBCL, Today, 04:38 AM
              3 responses
              23 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              11 responses
              1,423 views
              0 likes
              Last Post jculp
              by jculp
               
              Started by RubenCazorla, Today, 09:07 AM
              0 responses
              4 views
              0 likes
              Last Post RubenCazorla  
              Started by BarzTrading, Today, 07:25 AM
              2 responses
              29 views
              1 like
              Last Post BarzTrading  
              Started by devatechnologies, 04-14-2024, 02:58 PM
              3 responses
              21 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X