Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.programmer Subject: Re: Timezone string and converting dates to my time zone Date: Thu, 07 Jul 2011 09:27:51 +0100 Lines: 32 Message-ID: <97l908Fv3eU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net 4eT3K7ZRrthGidg53IswJQn51EUe/1o0e07SntM+/3cPYDbAVS Cancel-Lock: sha1:EymMrs6eK5Oq5qTdezJVfxbI4es= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5959 On 06/07/11 21:35, laredotornado wrote: > Hi, > > I'm using Java 1.6. I'm trying to convert a date that is of a > different time zone than what my machine is and I'm trying to get an > equivalent java.util.Date object for my time zone. So I'm trying ... > > public void setLEAD_ENTRY_DATE(Date lEAD_ENTRY_DATE) { > final Calendar cal = Calendar.getInstance(); > final String tz = > EnvironmentProperties.getInstance().get("database_time_zone").trim(); > cal.setTimeZone( TimeZone.getTimeZone(tz) ); > cal.setTime( lEAD_ENTRY_DATE ); > this.LEAD_ENTRY_DATE = cal.getTime(); > > but this isn't working (time passed in is the same as what I get > back). The time zone string is, "GMT-5:00", and I'm in central > standard time (GMT-6:00). Any hints on how to get this right are > greatly appreciated, - Dave > Date doesn't have a timezone, or it's always represented in UTC, depending on your perspective. It represents a specific instant in time, independent of timezone. You can convert from a Date to a wallclock date/time in a particular timezone (as represented by a Calendar) just as you do in your code. If you convert from that Calendar back to a Date you will get the same Date back. -- Nigel Wade