• Post Reply Bookmark Topic Watch Topic
  • New Topic

converting local date to gmt date or gmt hours  RSS feed

 
Greenhorn
Posts: 26
Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

i want to convert local time/date to gmt date /hours
can anybody suggest me any snippet..
the code should take care of longday and short day in uk if its not taken care by the timzone...
 
Ranch Hand
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at the API of Calendar and TimeZone Classes.

these both used together can give you what you want.

There is a setTimeZone() method also in Calendar class.
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kunal green wrote:
can anybody suggest me any snippet..

what have you tried???
 
kunal green
Greenhorn
Posts: 26
Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions,the code i tried is as follows:



This code is converting local time to corresponding gmt correctly but additionaly i want to find out whether a date is british long date/short date or not?
i am not sure this code will take care for that or not?

is there any api or way so that i can find whether a date is british long date or not?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The long integer which records the time for a Calendar object is a millisecond count since after 31st December 1969 and 1st January 1970. Although the moment it started from (called the epoch) was determined in GMT, the actual value is independent of time zones.
 
kunal green
Greenhorn
Posts: 26
Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry but still havien the same question,how to determine british long day and short day as far as i know long day has 25hrs and short one has 23 hrs i need to find out the long and short days among a given set of dates.probably the number of hours it has.does TimeZone take care of this???or i need to apply some different logic?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't explain about long date at all well.
The long day is the last Sunday in October and the short day is the last Sunday in March. I would have thought your time zone data would sort that out, but you need some sort of DST (=daylight saving time) data to go with that. DST data ought to be available readily, and Java™ frequently updates its DST data. But that does not mean GMT. It is when we change from GMT to BST (=British Summer Time).

I think this is beyond the level for "beginning", so I shall move this question.
 
kunal green
Greenhorn
Posts: 26
Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java provides APIS for this(timeZone.inDaylightTime(originalCal.getTime()),That helped me.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!