I have set a date field, and after fetching a value from it in the controller, i want to show the date field in the form of AM/PM. Can anyone help me in this?
Hi Rahul, You can use the format('hh:mm a'). Here 'a' denotes whether its AM/PM. DateTime myDateTime =DateTime.now(); String Timec = myDateTime.format('hh:mm a'); Refer the link : https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/ for more information. Please try this out and let me know if it works. Dont forget to mark it as best answer if it helps you. Thanks.
To convert Date/Time in 12 hrs format you can use:
I hope it helps you.
Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
All Answers
To convert Date/Time in 12 hrs format you can use:
I hope it helps you.
Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
You can use the format('hh:mm a'). Here 'a' denotes whether its AM/PM.
DateTime myDateTime =DateTime.now();
String Timec = myDateTime.format('hh:mm a');
Refer the link : https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/ for more information.
Please try this out and let me know if it works. Dont forget to mark it as best answer if it helps you.
Thanks.