Converting DateTime to format YYYY-MM-DDThh:mm:ssZ in Salesforce

System.debug(DateTime.now().format(‘yyyy-MM-dd\’T\’hh:mm:ss\’z\”));

It can be used in SOQL query. SOSL query returns the datetime in format(YYYY-MM-DDThh:mm:ssZ) so for comparison we need to convert it into above format.