New answers tagged

0

we recently used Apex JSON.deserialise method to convert DateTime String into GMT timezone, let us know if this may help in your scenario: String val = '2019-08-20T09:30:00-0800'; // PST Timezone //Convert to GMT Time Zone DateTime date1 = (DateTime)JSON.deserialize('"' + s + '"', DateTime.class); System.debug('GMT: ' + date1); //Convert to User Time Zone ...


1

System.debug(dateTimeVariable) always outputs a DateTime value in GMT. What you're looking at is 7:00:00 AM GMT and 9:00:00 AM GMT, respectively. To get the results you expect, use format() instead. Date myDate = Date.newInstance(2019, 11, 29); Time myTime = Time.newInstance(9,0,0,0); System.debug(Datetime.newInstance(myDate, myTime).format()); System....


3

You are witnessing the automating conversion of a GMT time (the numbers you passed in to DateTime.newInstance) to your local timezone. The mechanism helps when orgs have users working in multiple timezones See the various Datetime Class methods that output with and without this conversion.


0

It should just be a normal Date: var rightNow = new Date(); var record = new $M.Form_Details__c({Id='{!myId}',Last_Viewed_Timestamp__c:rightNow}); The Remote Objects framework automatically converts the value to the correct type for you.


2

You got the month and day backwards. Try System.Debug(DateTime.valueOf('2019-11-14 10:55:46 PM')); SPECS Notice it is counting Month 14 of 2019 which puts you in February of 2020. This might be counter intuitive and you might have expected an error saying month can't be greater than 12 but because of how parse() and valueOf() work, it just calculates ...


3

It should be small dd aka dd-MM-YYYY Date dStart = System.today(); System.debug(DateTime.newInstance(dStart.year(), dstart.month(), dstart.day()).format('dd-MM-YYYY')); //13-11-2019 Format method follows SimpleDateFormat and according to it Small d means date and Caps D means day of the year


0

It's not the neatest thing, but you could used the format() method of the DateTime class to convert the DateTime to a string with an adjusted timezone, and then convert it back to DateTime. More information about the format() method can be found here. String timeFormat = 'yyyy-MM-dd HH:mm:ss'; String timeZone = 'Pacific/Auckland'; DateTime convertedStart = ...


Top 50 recent answers are included