Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DateTime vs DateTimeOffset

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

    DateTime vs DateTimeOffset

    Hey guys, i´ve recently read that as far as Time Zone is concerned, Microsoft recognized using DateTimeOffset instead of DateTime. How is this at NT8. is it there also better to use DateTimeOffset, or is NT alway calculating on custom Time Zone?

    thanks for your respond!

    #2
    Hello sane1111,

    Thanks for your post.

    You could use DateTime in a NInjaScript strategy or indicator if you would like to get your machine's time. For example, see the sample code below.

    Code:
    Print("Current machine time: " + DateTime.Now);
    You could use Time[0] to get the current bar time stamp value. For example, see the sample code below.

    Code:
    Print("Bar time stamp: " + Time[0]);
    See this help guide page for more information about Time[ ]: https://ninjatrader.com/support/help...eries_time.htm

    See this publicly available link for more information about DateTime: https://docs.microsoft.com/en-us/dot...e?view=net-6.0

    And, see the attached example script. The example script demonstrates using the above prints.

    Let me know if I may assist further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks Brandon for your reply,

      I´m asking because of the following example.

      Code:
      DateTime dt = DateTime.UtcNow;
      Print(dt.ToString("HH:mm"));
      
      string apiReturn = dt.ToString("o");
      
      DateTime apiValue = DateTime.ParseExact(apiReturn, "o", null);
      Print(apiValue.ToString("HH:mm")); //
      Last edited by sane1111; 08-10-2022, 09:03 AM.

      Comment


        #4
        Sorry, i`ve made a mistake, because DateTime.Now works fine. But in this case DateTime does not work correctly. this is the question i have, if we also should work more with DateTimeOffset.

        thanksin advance!

        Comment


          #5
          Hello sane1111,

          Thanks for your note.

          This would fall under C# education and would go beyond the support we could provide. It would be up to you to decide whether to use DateTime or DateTimeOffset in your script.

          Ultimately, DateTime is used when referencing the machine's time and Time[0] would be used to reference a bar's timestamp.

          See this help guide page for information about creating time comparisons: https://ninjatrader.com/support/help...imeComparisons

          You could create a time comparison condition in the Strategy Builder and click the 'View code' button to see the generated syntax. Note that DateTime is used for time comparisons.

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          650 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X