• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Calendar Object - updateTime()

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

For doing Time Zone calculations, I was toying with the below code sniplet:



There is a seven hours different between Istanbul, and my developer machine, which is in America/New_York
Time Zone ID.

From the above sniplet, the results are:

Hour = 10
Minute = 16
Second = 31
DAY = 20
MONTH = 9
YEAR = 2010
BUILD SUCCESSFUL (total time: 0 seconds)

which in turn means , the time zone calculation isn't done, the values outputted belongs to local zone,so I jumped into calendar's source code and realized
that when I set day, month, etc.. the following block of code executes:



Here there is isTimeSet variable set to false, which is logical assuming that I am pushing new data to object,
changing its state. So since the state is changed, I need to force update somehow with a member function,
but I couldn't see one > again I was fooling around the source code, and I realized when I call getTimeInMillis()
function of the calendar, it forces an internal update, here is function itself:



So if I do not uncomment the part below from the code I posted in the beginning of this post, the algorithm never works correctly,
since it seems that the time information is never updated internally. After uncommenting the below section, i can get correct values
for the calculated time, date difference.



Outputs (7 hrs difference):

Hour = 17
Minute = 16
Second = 31
DAY = 20
MONTH = 9
YEAR = 2010
BUILD SUCCESSFUL (total time: 0 seconds)


So after this long, boring, maybe based on wrong assumptions? post, my question is how you guys do it?
It shouldn't be like this I hope? I should be doing smtg wrong.

Thanks all!



 
Beware the other head of science - it bites! Nibble on this message:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic