Dukascopy
 
 
Wiki JStore Search Login

JFOREX-3336 GMT Calender is wrong in CET TimeZone
 Post subject: JFOREX-3336 GMT Calender is wrong in CET TimeZone Post rating: 0   New post Posted: Mon 21 Nov, 2011, 15:39 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 404
Location: Germany, Munich
I live and run JForex in CET TimeZone.
JForex displays charts and ticks in GMT TimeZone only.
Therefore I want to set the parameters in the GMT TimeZone.
I tried the following

@Configurable("Start Date 1")                         
public Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));


but the Calendar object is always displayed in CET time (offset 1 h at the moment).
It should be displayed in the TimeZone I have select in the programed code!


 
 Post subject: Re: JFOREX-3336 GMT Calender is wrong in CET TimeZone Post rating: 0   New post Posted: Thu 24 Nov, 2011, 16:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6115
Calendar has a TimeZone property, but setting or modifying it does not convert the date and time that the calendar holds to a different timezone. I.e. calendar.getTime() always returns the same set value independent from calendar's time zone.
On the other hand, e.g. calendar.get(Calendar.HOUR) / calendar.get(Calendar.HOUR_OF_DAY) returns the correct hour corresponding to calendar's time zone.

Please, use a DateFormat object with corresponding TimeZone set (GMT/UTC in your case) to parse/format Calendar / Date objects, e.g:

 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{ setTimeZone(TimeZone.getTimeZone("GMT 0")); }}; 
 Calendar calendar = Calendar.getInstance();
 System.out.println(String.format("Default TimeZone: %1$s; Current Date: %2$s; Formatted Date to GMT TimeZone: %3$s; Parsed Date from GMT TimeZone: %4$s",
                                          TimeZone.getDefault().getDisplayName(), // 1
                                          calendar.getTime(), // 2
                                          formatter.format(calendar.getTime()), // 3
                                          formatter.parse(formatter.format(calendar.getTime())))); // 4


Prints out in such case:
"Default TimeZone: Eastern European Time; Current Date: Thu Nov 24 16:46:47 EET 2011; Formatted Date to GMT TimeZone: 2011-11-24 14:46:47.200+0000; Parsed Date from GMT TimeZone: Thu Nov 24 16:46:47 EET 2011"

Additionally, we have fixed the issue with @Configurable strategy parameter with java.util.Calendar type which had not been supported.


 

Jump to:  

cron
  © 1998-2011 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