Which code should you insert at line 04?

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.)

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.)

Answer:



Leave a Reply 15

Your email address will not be published. Required fields are marked *


zafr

zafr

date format, it wrong it should be {0:mm/dd/yy}

zerocool

zerocool

No, but it’s difficult to see! Take a look at the wildcards:
‘MM’: would give the month.
‘mm’: gives MINUTES!!

Tamil

Tamil

I worked out the correct code snippets:

string output = String.Format(“Temperature at {0:t} {0:d} temp {1:N2}”, DateTime.Now, 25);

kinnoy5

kinnoy5

The answer is
string output = String.Format(“Temperature at {0:t} {0:d} temp {1:N2}”, DateTime.Now, 25);

{0:d} refer to ShortDate

ette

ette

You are right

宾宾

宾宾

The answer is:
//modify the vlaue of en-us to Culture.
Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-us”);
string msg = string.Format(“Temperature at {0:t} on {0:d} : {1:N2}”, DateTime.Now, 20);

j

j

Correct
Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-us”);
string msg = string.Format(“Temperature at {0:t} on {0:d} : {1:N2}”, DateTime.Now, 20);

sandip

sandip

{0:t}
{0:d}
{1:N2}

ASV

ASV

if the year is 2013, then it must be “yyyy”. But there is no such Option.

Jiping Wang

Jiping Wang

{0:t}
{0:d}
{1:N2}

confirmed in Visual Studio:

string.Format(“time={0:t} date={0:d} temp={1:N2}”, DateTime.Now, 2)
——————————————
time=01:24 AM date=05/10/2016 temp=2.00

Artem

Artem

{0:d} and {0:t} is culture specific. For me this code print
time=23:43 date=14.02.2017
If I add before
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
then work correctly.

msdn

msdn

{0:t}
{0:d}
{1:N2}

Alisher

Alisher

string output = String.Format(“Temperature at{0:t} {0:d} temp {1:N2}”, DateTime.Now, 45);

{0:t}
{0:d}
{1:N2}