You need to sign in to do that
Don't have an account?
Mint
Retrieving Date field from query results (Java, salesforce)
Hi,
I am very new to java development for SalesForce integration.
I got SObject as a result of query from the SalesForce. Now, I need to retrieve TimeZone information and the timestamp from the SObject's "CreatedDate" column.
Can anyone help me how to retrieve this information? I see the following classes related to this:
GetServerTimestamp.java
GetServerTimestampResponse.java
GetServerTimestampResult.java
But, don't know how to use them.
Any help is greately apprciated.
Thanks.
All Answers
Sorry, I didn't mention that I am using partner wsdl. The examples do not have anything for partner wsdl.
Thanks.
Looks like CreatedDate is in ISO 8601 format:
2008-07-29T18:35:18.000Z
You can use Joda Time to parse the ISO 8601 string into a DateTime object. Once you have the DateTime object, you can easily get the time zone information. See the Joda Time documentation for details.
You can also use the standard library classes (Calendar, etc) but Joda Time has a much better API, is thread safe, etc.
Thanks so much all of you, for sharing this valuable information. This is what I am doing:
dateFormat.setTimeZone(tz);
Date utcDate = dateFormat.parse(utcTime);
cal.setTime(utcDate);
This converts the utcTime from the SalesForce to my local time.
Try just this:
String utcTime = (String) sObjAttributes.get("CreatedDate");
DateTime dt = new DateTime(utcTime);
Since the string is already in ISO8601 format, you shouldn't need to do all that work to parse it. You now have a DateTime in UTC time. To see what the time would be in another time zone:
DateTime dtLondon = dt.withZone(DateTimeZone.forID("Europe/London"));
Appreciate your reply. This is definitely a better way of doing it.
Thanks.
Hello,
Please share your solution if you have found it correctly..
thanks