Select your Language

Formate Date and Time in Apex

Date formate using in Salesforce:


Example:

DateTime dt = Datetime.now();
String strTimeInAMorPM = dt.format('MMMMM dd, yyyy hh:mm:ss a');
System.debug('time in am and pm ==> '+strTimeInAMorPM); 

String strTimeInWeek = dt.format('MMMMM dd, yyyy EEEE');
System.debug('strTimeInWeek ==> '+strTimeInWeek); 

String strTimezone = dt.format('MMMMM dd, yyyy z');
System.debug('strTimezone ==> '+strTimezone); 
Output:


Reference by: 
https://www.salesforcecodecrack.com/2020/04/format-dates-and-time-using-apex-in.html

No comments:

Post a Comment