
5 件の回答
To get the current date and time in GMT, use System.now().
To convert a DateTime to a specific time zone, you can use DateTime methods such as format().
DateTime nowGMT = System.now();
String nowString = nowGMT.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'GMT');
System.debug('Current GMT Time: ' + nowString);
DateTime Rounding: If your code is performing any arithmetic operations on DateTime fields, ensure that it is not inadvertently causing rounding. For example, adding or subtracting durations might round the DateTime to the nearest hour if not handled correctly.
DateTime currentTime = System.now();
DateTime roundedTime = currentTime.addHours(0); // Ensure no rounding occurs