Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Timezone string and converting dates to my time zone

Reply
Thread Tools

Timezone string and converting dates to my time zone

 
 
laredotornado
Guest
Posts: n/a
 
      07-06-2011
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

 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      07-06-2011
On 7/6/2011 1:35 PM, laredotornado wrote:

> 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



Wouldn't your own current time zone just be TimeZone.getDefault()?


 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      07-07-2011
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-08-2011
On Wed, 6 Jul 2011 13:35:39 -0700 (PDT), laredotornado
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>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.


see http://mindprod.com/jgloss/timezone.html
http://mindprod.com/jgloss/calendar.html
for recipes for the usual transforms.
--
Roedy Green Canadian Mind Products
http://mindprod.com
One thing I love about having a website, is that when I complain about
something, I only have to do it once. It saves me endless hours of grumbling.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting time historic GMT to local time by specifying a timezone Tharinda C++ 3 08-25-2010 05:32 PM
Convert windows TimeZone to Java TimeZone asaf Java 3 09-11-2006 05:40 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
GMT time to local time, according to timezone and summer/winter time. David Joseph Bonnici Perl Misc 1 05-15-2005 09:15 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments