function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
plpl 

time zone

Hi,

I notice the time in sforce and my local time is 4 hours difference. I assume you use GMT. My problem is when I create filter using field "lastModifiedDate". I have to do the hack: added 4 hours to my startDate and endDate because it only take Java Date object as "value". Any solution for me. I don't like the hack but I do need this to be solved in a nice way.


Date startDate = new Date(startDate.getTime()+14400000);

Date startDate = new Date(endDate.getTime()+14400000);



Vector filter
= new Vector();

Hashtable h1
= new Hashtable();
//first
h1.put(
"field", "lastModifiedDate");
h1.put(
"operator", "greater than");
h1.put(
"value", startDate);
//second
Hashtable h2
= new Hashtable();
h2.put(
"field","lastModifiedDate");
h2.put(
"operator","less than");
h2.put(
"value", endDate);

Vector filterVec
= new Vector();
filterVec.add(h1);
filterVec.add(h2);
//first and second
Hashtable h
= new Hashtable();
h.put(
"operator","and");
h.put(
"value", filterVec);

filter.add(h);

adamgadamg

Yes, my understanding is the dates are GMT; for example this is a date I get back using SOAP/API 2.0:

2003-07-25T18:51:05+0000

I use the Java calendar object to manage date/times, and suggest you do the same, it has roll functions that let you easily handle date issues (note there are seperate APIs for converted between Time Zones in the Calendar object.) For example:

Calendar jc = Calendar.getInstance();

jc.roll(Calendar.DAY_OF_YEAR, -1);

You will also likely want to use a Date Formatter object, like this:

SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");

Date d = jdf.parse(nValue);

Which will give you a Date object from the string to use as you wish. Future versions of the API will likely return a Date object directly, saving you the effort of having to cast the result.