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

Server time using REST API

Any way to get SF server time using REST API ?



Mohith Kumar ShrivastavaMohith Kumar Shrivastava
global with sharing class SFA_GetCurrentServerDateTime {

//This is a wrapper class which will enclose the long response data string and return to external system

global class ResponseWrapper{
public String currentServerTime;

//@ Method Name: returnCurrentServerTime
//@ Description: This RESTful method returns the SFDC server timestamp to the calling program 
//@ Arguments : none 
//@ Returns : ResponseWrapper Object 

global static ResponseWrapper returnCurrentServerTime(){ 

String dateInFormat = newDate.formatGMT('yyyy-MM-dd HH:mm:ss');
ResponseWrapper resWrap=new ResponseWrapper();

system.debug('Server time being sent:'+dateInFormat);
return resWrap;

 Please find the above code .The standard REST API does not support this feature.Hence the above apex wrapper will generate the necesary API.