Timezone string and converting dates to my time zone

Discussion in 'Java' started by laredotornado, Jul 6, 2011.

  1. 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
     
    laredotornado, Jul 6, 2011
    #1
    1. Advertising

  2. laredotornado

    markspace Guest

    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()?
     
    markspace, Jul 6, 2011
    #2
    1. Advertising

  3. laredotornado

    Nigel Wade Guest

    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
     
    Nigel Wade, Jul 7, 2011
    #3
  4. laredotornado

    Roedy Green Guest

    On Wed, 6 Jul 2011 13:35:39 -0700 (PDT), laredotornado
    <> 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.
     
    Roedy Green, Jul 8, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    904
    Rob Schieber
    Sep 30, 2005
  2. Tharinda
    Replies:
    3
    Views:
    1,257
    peter koch
    Aug 25, 2010
  3. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    231
    Mark Schupp
    Aug 9, 2004
  4. Stéphane Klein
    Replies:
    0
    Views:
    78
    Stéphane Klein
    Dec 2, 2013
  5. Stuart Bishop
    Replies:
    0
    Views:
    69
    Stuart Bishop
    Dec 3, 2013
Loading...

Share This Page