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

European date format and strings

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

    European date format and strings

    I have an indicator which compares some strings that hold dates in US format of "MM/DD/YYYY hh:mm:ss" and it has come to my attention from a European user that the indicator fails because of the difference in the Date format (DD/MM/YYYY). To get around it I have used this:

    if(CultureInfo.CurrentCulture.Name == "en-US")
    {
    Do something with the US formatted strings
    }
    else
    {
    Do something with alternate Euro strings
    }

    Since working with time and dates makes my head spin, my question is should I be doing this in a better way?

    Dan
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    #2
    Dan, one idea would be working for example into UTC only and then converting back to user time as needed -

    Converts the value of the current DateTime object to Coordinated Universal Time (UTC).


    If you don't want to work with DateTime objects, you could work with ToTime() & ToDay() to convert those to integers.



    BertrandNinjaTrader Customer Service

    Comment


      #3
      Dan,

      if it is you who creates the strings, you could use the invariant format for the time/date-string-formatting:

      DateTimeFormatInfo.InvariantInfo;

      It doesn't change the used time zones but it provides an unique format very similar to the american style.

      Regards
      Ralph

      P.S: There is no european style for Date/Time. For example even the string format of british an german Date/Time values would differ.
      Last edited by Ralph; 03-24-2010, 06:14 AM.

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        Dan, one idea would be working for example into UTC only and then converting back to user time as needed -

        Converts the value of the current DateTime object to Coordinated Universal Time (UTC).


        If you don't want to work with DateTime objects, you could work with ToTime() & ToDay() to convert those to integers.



        http://www.ninjatrader-support.com/H...eV6/ToDay.html
        Thanks Bertrand but it is the Date format that causes the problem, not Time so I believe using any conversions to UTC would have no effect. Ralph, are you saying there is a format for Date strings that can be read universally? I may need to get more info from you about that. Dan
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Dan, you're right would apply only to the time component as a quick test showed - perhaps the the From / To binary method is of value for your endavour?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Dan, here is a quick test. I executed the following code with german time:

            Print(Time[0].ToString());
            Print(Time[
            0].ToString(DateTimeFormatInfo.InvariantInfo));

            And here is the result. The first line is the native string and the second line the invariant version. If you execute this code on your side, your invariant result should have the same syntax:

            25.03.2010 18:39:02
            03/25/2010 18:39:02

            Don't forget to insert:
            using System.Globalization;

            Regards,
            Ralph

            Comment


              #7
              On a wider note, I'd like to remind you about this thread (which is closed, but not resolved)



              I realise it's not on your radar much, but it's really irritating to those of us outside the US..

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              2 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              11 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              12 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Working...
              X