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
ClariusClarius 

Server time using REST API

Any way to get SF server time using REST API ?

 

Thanks.....

Mohith Kumar ShrivastavaMohith Kumar Shrivastava
@RestResource(urlMapping='/currentservertime')
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 

@HttpGet
global static ResponseWrapper returnCurrentServerTime(){ 

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

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.