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

Proper code for displaying time in 24hr format

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

    Proper code for displaying time in 24hr format

    I have a news indicator that when 12hr format is selected, the time properly displays. However, if 24hr format is selected, the time is cutoff in display, ie. 15:0 instead of 15:00 (see screenshots).

    Below is the only code I find regarding 24hr format. What would I be looking for and/or what edits do I need?

    Screenshots:
    Click image for larger version

Name:	nt-news-time-1.jpg
Views:	20
Size:	4.8 KB
ID:	1291392
    Click image for larger version

Name:	nt-news-time-2.jpg
Views:	20
Size:	3.7 KB
ID:	1291393

    Code:
    //set text layouts
                            foreach(var field_name in columns_to_show)    {
                                        var value =  currentItem.GetType().GetProperty(field_name).GetValue(currentItem, null);
                                        var value_final=  ( field_name != "Time" ? value :  (   (!_ShowDayNumber ? "" : "(" +((dynamic)value).Day.ToString() +") ") +( _ShowIn24hr_Format ? (((dynamic)value).Hour).ToString()+":"+(((dynamic)value).Minute).ToString() : ((dynamic)value).ToShortTimeString() )  )  ).ToString() ;
                                newLayout.text_layouts[field_name]= new TextLayout(Core.Globals.DirectWriteFactory, value_final, _textformats["newsItem"], ChartPanel.W, (float)_newsItemFont.Size);
                                //Now that we have the layout, measure the widest for each of its items
                                widestTexts[field_name]= Math.Max( ((dynamic) newLayout.text_layouts[field_name]).Metrics.Width,  (widestTexts.ContainsKey(field_name) ? widestTexts[field_name] : 0 ) );​
    Attached Files

    #2
    Hello sastrades,

    Thank you for your post.

    This seems to have to do with how the numbers are formatted when you call ToString(). We have a general page about formatting numbers here:


    More information about formatting numbers may be found using C# resources, such as the following publicly available links:
    In this article, learn to use standard numeric format strings to format common numeric types into text representations in .NET.

    Learn how to create a custom numeric format string to format numeric data in .NET. A custom numeric format string has one or more custom numeric specifiers.


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      This seems to have to do with how the numbers are formatted when you call ToString()
      Yep, thanks! I needed to edit this to include "D2"...

      Code:
      +(((dynamic)value).Minute).ToString("D2")

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by PeakTry, Today, 10:49 AM
      0 responses
      2 views
      0 likes
      Last Post PeakTry
      by PeakTry
       
      Started by llanqui, Today, 10:32 AM
      0 responses
      4 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,992 views
      3 likes
      Last Post johntraderuser2  
      Started by TAJTrades, Today, 09:46 AM
      0 responses
      8 views
      0 likes
      Last Post TAJTrades  
      Started by rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Working...
      X