exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 1 question 88 discussion

Actual exam question from Microsoft's 70-483
Question #: 88
Topic #: 1
[All 70-483 Questions]

HOTSPOT -
You are developing an application in C#.
The application will display the temperature and the time at which the temperature was recorded. You have the following method (line numbers are included for reference only):

You need to ensure that the message displayed in the lblMessage object shows the time formatted according to the following requirements:
✑ The time must be formatted as hour:minute AM/PM, for example 2:00 PM.
✑ The date must be formatted as month/day/year, for example 04/21/2013.
✑ The temperature must be formatted to have two decimal places, for example 23.45.
Which code should you insert at line 04? (To answer, select the appropriate options in the answer area.)
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:

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
Mitsoshima
Highly Voted 6 years ago
The answer should be in order: {0:t} {0:mm/dd/yyyy} {1:N2}
upvoted 13 times
Khanyie
5 years, 7 months ago
isn't it a {0:t} {0:d} {1:N2}
upvoted 33 times
natsk8freak
5 years, 6 months ago
Both "t" and "d" format specifiers are shorthand formats. They will output the correct format. DateTime dt = new DateTime(); Console.WriteLine("{0:t}", dt); Console.WriteLine("{0:d}", dt); Console.WriteLine("{0:mm/dd/yyy}", dt); Produces the following output: 12:00 AM 1/1/0001 00/01/001
upvoted 3 times
...
...
Ibelal
5 years, 7 months ago
mm for minutes not month
upvoted 6 times
...
...
founderDev
Highly Voted 5 years, 5 months ago
Correct answer => {0:t} {0:d} {1:N2}
upvoted 12 times
...
DaGrooveNL
Most Recent 4 years, 5 months ago
FINAL ANSWER: {0:hh:mm:tt} {0:MM/dd/yyyy} {1:N2} Which does not rely upon your default culture.
upvoted 1 times
M62
4 years, 5 months ago
Agreed ,except the first two are not provided options. I believe the question is probably missing some detail such as assume culture is en-us.
upvoted 1 times
...
...
TomasRafaj
4 years, 5 months ago
Jesus, was really confused of these all questions, but some of them are right and the results of tests are: // yyyy:MM:dd, hh:mm:ss DateTime date = new DateTime(2020, 02, 20, 18, 50, 40); double temp = 25; Console.WriteLine(string.Format("Temperature at {0:t} on {0:d}: {1:N2}", date, temp)); // Temperature at 18:50 on 20. 2. 2020: 25,00 - NOK Console.WriteLine(string.Format("Temperature at {0:hh:mm} on {0:MM/dd/yyyy}: {1:N2}", date, temp)); // Temperature at 06:50 on 02. 20. 2020: 25,00 - OK
upvoted 1 times
...
noussa
4 years, 5 months ago
I 've been really confused with this question and all those replies so I digged a bit and I found the same example on MS docs pages: string s = String.Format("It is now {0:d} at {0:t}", DateTime.Now); Console.WriteLine(s); // Output similar to: 'It is now 4/10/2015 at 10:04 AM' So correct answer is: {0:t} {0:d} {1:N2} This is the link: https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0#control-formatting
upvoted 1 times
hseagraves
4 years, 5 months ago
The only reason I would go with {0:MM/dd/yyyy} for the date is because the question shows the date with leading zeros. Personally I hate leading zeros but hey.
upvoted 1 times
...
hseagraves
4 years, 5 months ago
Oops but I guess since the answer doesn't have mm in caps then I would choose {0:d}
upvoted 1 times
...
...
Kilsimon
4 years, 8 months ago
As some people have written, it depends on the culture. t and d is a shorthand that takes the current culture and uses that to determine what the output is. If you want to be sure to get the correct values, the answer is: {0:hh:mm:tt} on {0:MM/dd/yyyy} : {1:N2}. Links for reference on DateTime. https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1 https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#ShortDate https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#ShortTime
upvoted 4 times
...
Mona30
4 years, 9 months ago
public static void Main() { DisplayTemperature(DateTime.Now, 23.45); Console.ReadLine(); } private static void DisplayTemperature(DateTime date, double temp) { string output; output = string.Format("Temp at {0:t} on {0:d} {1:N2}", date, temp); string message = output; Console.WriteLine(output); } Output: Temp at 1:49 PM on 8/6/2020 23.45
upvoted 1 times
...
ThomT
4 years, 9 months ago
The answers don't work for me, this does however:: string output = string.Format("Temperature at {0:hh:mm:tt} on {0:MM/dd/yyyy} : {1:N2}", date, temp);
upvoted 2 times
...
HgstExam
4 years, 10 months ago
Depends on CultureInfo: double temp = 123d; var now = DateTime.Now; Console.WriteLine("{0:t} {0:d} {1:N2}",now,temp); Console.WriteLine("{0:hh:mm tt} {0:MM/dd/yyyy} {1:N2}",now,temp);
upvoted 2 times
...
Bart_v_M
4 years, 10 months ago
{0:t} does not give time in AM/PM in my situation, it just gives a 24 hour clock from 00:00 to 23:59. I have to use {0:hh:mm tt} to get the time in AM/PM, and I have to set CurrentCulture to "us-US" or "en-UK". The last two answers {0:d} and {1:N2} are correct.
upvoted 1 times
eliasalg
4 years, 9 months ago
Exactly: Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:t} {0:d} {1:N2}", DateTime.Now, (double)25.699)); Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0:t} {0:d} {1:N2}", DateTime.Now, (double)25.699)); Console.WriteLine(string.Format(CultureInfo.GetCultureInfo("en-us"), "{0:t} {0:d} {1:N2}", DateTime.Now, (double)25.699)); Console.WriteLine(string.Format(CultureInfo.GetCultureInfo("es-es"), "{0:t} {0:d} {1:N2}", DateTime.Now, (double)25.699)); OUTPUT 17:11 09/11/2020 25.70 17:11 11/09/2020 25.70 5:11 PM 9/11/2020 25.70 17:11 11/09/2020 25,70
upvoted 1 times
...
...
Karthi1105
4 years, 10 months ago
Verified in Visual studio!! {0:t} , {0:MM/dd/yyyy} -- It is not small mm , {1:N2}
upvoted 2 times
...
justpassingexam
4 years, 10 months ago
The answers depend on culture info
upvoted 4 times
...
mohmou
4 years, 11 months ago
mm => Minute MM => Month
upvoted 2 times
...
abelbm
5 years, 2 months ago
The answer is {0:t} {0:MM/dd/yyyy} but this one doesn't exists so use {0:d} {1:N2}
upvoted 6 times
...
VladWork
5 years, 2 months ago
{0:t} {0:d} {1:N2}
upvoted 5 times
...
ArunPrem
5 years, 2 months ago
Correct answer: string.Format("Temperature at {0:t} on {0:dd/mm/yyyy}: {1:N2}", dt, temp);
upvoted 1 times
WTH
5 years, 1 month ago
Not. It should be string.Format("Temperature at {0:t} on {0:MM/dd/yyyy}: {1:N2}", dt, temp);
upvoted 4 times
...
...
rhysabray
5 years, 4 months ago
I am curious as to why the first answer would be {0:t}? To me, {0:t} gives a 24 hour representation and {0:hh:mm} gives a 12 hour representation. The question asks for the time to be represented as AM/PM and gives 2PM as an example which is 12 hour. Next, the second part doesn't have a correct answer for me, but that may be to do with DateTime being set to UK standards; {0:d} gives day/month/year to display. Whereas {0:mm/dd/yyyy} gives MINUTES/day/year because of lowercase mm. This could be a typo and perhaps should say {0:MM/dd/yyyy}. So I believe that the full answer should be: - {0:hh:mm} - {0:MM/dd/yyyy} - {1:N2}
upvoted 6 times
ReDo
5 years, 3 months ago
if you just run this in a console app: DateTime dt = DateTime.Now; Console.WriteLine("{0:t}", dt); Console.WriteLine("{0:d}", dt); Console.WriteLine("{0:mm/dd/yyyy}", dt); This is the output: 11:01 AM 3/17/2020 01/17/2020 (mm is for minutes not months)
upvoted 3 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 ...