New answers tagged

3

With thanks to @Phil W whose feedback put me on the right track, I've modified my code to the following which seems to work: public String formatForGermany(Datetime targetTime) { return this.format(targetTime, 'Europe/Berlin'); } private String format(Datetime appointmentDatetime, String zone) { Integer offset = TimeZone.getTimeZone(zone) ...


3

One option is to take the UTC Datetime value, convert it to Berlin time then extract the date and time (using the dateGmt() and timeGmt() methods on Datetime) values and present these as separate Date and Time values. Note that Salesforce only applies user-timezone-processing to Datetime values. Separate Date and Time values have no timezone so no offsetting ...


0

Note the time needs to be transformed to GMT based on the timezone: String[] dateTimeSplit = String.valueOf(assetActivity.get('actstart') .getValue()).split(' '); String[] dateSplit = dateTimeSplit[0].split('-'); String[] timeSplit = dateTimeSplit[1].split(':'); //you will have to write a function that converts the time to GMT based on the ...


0

Datetime includes methods such as addHours, addMinutes and addSeconds that you can use with positive or negative values. For example: Datetime value = System.now(); TimeZone to = TimeZone.getTimeZone('America/Argentina/Buenos_Aires'); value = value.addSeconds(to.getOffset(value) / 1000); Note, however, the representation of date/time won't tell you this is ...


4

Simply use Salesforce's TimeZone class, and specifically the TimeZone.getOffset method. You can probably do something like: TimeZone germanyTZ = TimeZone.getTimeZone('Europe/Berlin'); System.debug(germanyTZ.getID()); appointment = appointment.addSeconds(germanyTZ.getOffset(appointment) / 1000); System.debug(appointment); Note that when looking to get a ...


3

All DateTimes in Salesforce are stored as GMT/UTC so that they can easily be shifted based on a user's timezone (a necessity in any organization where users are logging in from multiple time zones). So if you see GMT in the database, that's as designed. If the time isn't being shown properly to the end user, consider using a component that displays a ...


1

Thank you everyone who viewed! Figured this out right now, I can not believe I was this blind, but it seems that from the default date 1900,1,8 above I was missing the time element to make the hours come into play. By adding 16:00:00 to each instance of this, I got my correct rounding needed! Just in case anyone else is affected by the same issue, wanted to ...


Top 50 recent answers are included