DateTime new instance using Apex in Salesforce

DateTime new instance using Apex in Salesforce

 Sample Code:

/*Constructs a DateTime from the specified date and time in the local time zone.*/
Date myDate = Date.newInstance( 2020, 10, 30 );
Time myTime = Time.newInstance( 3, 3, 3, 0 );
DateTime objDT = DateTime.newInstance( myDate, myTime );
/* Using format() since teh objDT return value will be in GMT */
system.debug( 'Date Time is ' + objDT.format() );

Output:

Leave a Reply