A is the correct and please refer the bellow discussion
https://salesforce.stackexchange.com/questions/154024/display-string-datetime-in-current-user-locale
the correct answer is A. A and C are very close but differ in the following way.
A is the date format method- it returns the date as string using the user locale.
C is a string method- it returns a string of the date specified in the standard format of YYYY-MM-DD. my locale is english(canada) the format is YYYY-MM-DD so seems that C is correct ans. But here is the catch. when I change my local to French(France) the date format of my local becomes DD/MM/YYYY. In this case String method will not work. Thus A is the ans.
valueOf(datetimeToConvert)
Returns a String that represents the specified Datetime in the standard “yyyy-MM-dd HH:mm:ss” format for the local time zone.
the correct answer is A. A and C are very close but differ in the following way.
A is the date format method- it returns the date as string using the user locale.
C is a string method- it returns a string of the date specified in the standard format of YYYY-MM-DD. my locale is english(canada) the format is YYYY-MM-DD so seems that C is correct ans. But here is the catch. when I change my local to French(France) the date format of my local becomes DD/MM/YYYY. In this case String method will not work. Thus A is the ans.
Date.format() returns the Date as a string using the locale of the context user
String.valueOf() returns a String that represents the specified Datetime in the standard “yyyy-MM-dd HH:mm:ss” format for the local time zone.
Ans is A
format() - Returns the Date as a string using the locale of the context user
// In American-English locale
date myDate = date.newInstance(2001, 3, 21);
String dayString = myDate.format();
system.assertEquals('3/21/2001', dayString);
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_date.htm#apex_System_Date_format
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Shah743
Highly Voted 2 years, 2 months agosinghkar
Highly Voted 2 years, 2 months agosanto_aj
Most Recent 3 months, 3 weeks agosanto_aj
4 months agoopqrst
4 months, 4 weeks agoTing21
5 months agokarappo
6 months, 1 week agoram12313
4 months, 4 weeks agothneeb
6 months, 3 weeks agosf2022
8 months, 2 weeks agovm1406
10 months agoCaiXiDan
1 year, 1 month ago