expert
expert

Reputation: 30135

Is it possible to make DateBox work in time-zone other than in one that is set in browser?

Is it possible to make DateBox work in time-zone other than in one that is set in browser ?

In my case time-zone should change depending on other information in form.

Based on info in the documentation there is no built-in way to do that. Could you suggest how you would approach it ?

Upvotes: 0

Views: 1697

Answers (1)

Peter Jamieson
Peter Jamieson

Reputation: 745

I did this by creating a class implementing DateBox.Format: -

public class MyDateFormat implements DateBox.Format
{

    private TimeZone tz;

    public MyDateFormat(TimeZone tz)
    {
        this.tz = tz;
    }

    @Override
    public String format(DateBox arg0, Date arg1)
    {
        if(arg1 == null)
        {
            return null;
        }
        return DateTimeFormat.getFormat("dd MMM yyyy hh:mm:ss Z").format(arg1, tz);
    }

    @Override
    public Date parse(DateBox arg0, String arg1, boolean arg2)
    {
        return DateTimeFormat.getFormat("dd MMM yyyy hh:mm:ss Z").parse(arg1);
    }

    @Override
    public void reset(DateBox arg0, boolean arg1)
    {

    }
}

and then: -

dateBox.setFormat(new MyDateFormat(tz));

Upvotes: 4

Related Questions