Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

How to get the server time and local machine time when a strategy is onStart?
 Post subject: How to get the server time and local machine time when a strategy is onStart? Post rating: 0   New post Posted: Thu 16 Aug, 2012, 03:41 

User rating: 0
Joined: Thu 16 Aug, 2012, 03:29
Posts: 26
Excuse me,

I am a beginner on JForex.

I have a few simple questions and wish you could kindly give me a hand.

Please tell me how to get the server time and local machine time when a strategy is onStart.

I used the example already in JForex-SDK and it runs like this:
"
2012-08-15 21:42:12.525 INFO Main - Starting strategy
Strategy "test_01" is started at 2012-08-16 02:12:16.307 GMT on the local computer with no parameters
"

I want to get the GMT time like "2012-08-16 02:12:16.307" in the example above.
I wonder what the time "2012-08-15 21:42:12.525 INFO" means.

Please enlighten me on this point.

Thank you so much!


 
 Post subject: Re: How to get the server time and local machine time when a strategy is onStart? Post rating: 0   New post Posted: Thu 16 Aug, 2012, 08:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
blackkettle wrote:
I want to get the GMT time like "2012-08-16 02:12:16.307" in the example above.
See https://www.dukascopy.com/wiki/#IConsole/Logging_values
blackkettle wrote:
I wonder what the time "2012-08-15 21:42:12.525 INFO" means.
It is log4j logger timestamp, the format of which is determined by the rc\log4j.properties file. Read more on log4j here https://logging.apache.org/log4j/1.2/.


 
 Post subject: Re: How to get the server time and local machine time when a strategy is onStart? Post rating: 0   New post Posted: Thu 16 Aug, 2012, 14:40 

User rating: 0
Joined: Thu 16 Aug, 2012, 03:29
Posts: 26
Thank you so much!


 
 Post subject: Re: How to get the server time and local machine time when a strategy is onStart? Post rating: 0   New post Posted: Fri 17 Aug, 2012, 03:59 

User rating: 0
Joined: Thu 16 Aug, 2012, 03:29
Posts: 26
API Support wrote:
blackkettle wrote:
I want to get the GMT time like "2012-08-16 02:12:16.307" in the example above.
See https://www.dukascopy.com/wiki/#IConsole/Logging_values
blackkettle wrote:
I wonder what the time "2012-08-15 21:42:12.525 INFO" means.
It is log4j logger timestamp, the format of which is determined by the rc\log4j.properties file. Read more on log4j here https://logging.apache.org/log4j/1.2/.


By the way, could you please tell me how to get the local machine time?

It seems that the statement "Calendar.getInstance().getTime();" just get the time on the server side.

Thank you so much!


 
The Best Answer  Post subject: Re: How to get the server time and local machine time when a strategy is onStart? Post rating: 0   New post Posted: Thu 23 Aug, 2012, 15:18 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If strategy receives server time only if is run on LIVE client and in "remote run" mode.
Otherwise Calendar.getInstance().getTime(); returns time on your machine.
To correctly output time in your location you must change the time zone value in the following line:
setTimeZone(TimeZone.getTimeZone("GMT"));


Basically, you can use this function:
public String dateToStr(long time) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {
         {
            setTimeZone(TimeZone.getTimeZone("GMT"));
         }
      };
      return sdf.format(time);
   }


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com