exam questions

Exam Certified Platform Developer II All Questions

View all questions & answers for the Certified Platform Developer II exam

Exam Certified Platform Developer II topic 1 question 49 discussion

Actual exam question from Salesforce's Certified Platform Developer II
Question #: 49
Topic #: 1
[All Certified Platform Developer II Questions]

Which method should be used to convert a Date to a String in the current user's locale?

  • A. Date.format
  • B. String.format
  • C. String.valueOf
  • D. Date.parse
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Shah743
Highly Voted 2 years, 2 months ago
Answer should be A.
upvoted 10 times
...
singhkar
Highly Voted 2 years, 2 months ago
A is the correct and please refer the bellow discussion https://salesforce.stackexchange.com/questions/154024/display-string-datetime-in-current-user-locale
upvoted 7 times
...
santo_aj
Most Recent 3 months, 3 weeks ago
Selected Answer: A
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.
upvoted 1 times
...
santo_aj
4 months ago
Correct answer is A. https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_date.htm#apex_System_Date_format
upvoted 1 times
...
opqrst
4 months, 4 weeks ago
Selected Answer: C
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.
upvoted 1 times
...
Ting21
5 months ago
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.
upvoted 2 times
...
karappo
6 months, 1 week ago
date.format() return local locale (set in your device like computer, phone) String.ValueOf return user locale (set in SF)
upvoted 1 times
ram12313
4 months, 4 weeks ago
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.
upvoted 1 times
...
...
thneeb
6 months, 3 weeks ago
Selected Answer: A
A is correct.
upvoted 1 times
...
sf2022
8 months, 2 weeks ago
Selected Answer: A
Anwser is A since it is in local time
upvoted 1 times
...
vm1406
10 months ago
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
upvoted 1 times
...
CaiXiDan
1 year, 1 month ago
I had try A and C, both work. What the hell?
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago