Which code segment should you use?

You are developing a fiscal report for a customer.
Your customer has a main office in the United States and a satellite office in Mexico.
You need to ensure that when users in the satellite office generate the report, the current date is displayed in Mexican Spanish format.
Which code segment should you use?

You are developing a fiscal report for a customer.
Your customer has a main office in the United States and a satellite office in Mexico.
You need to ensure that when users in the satellite office generate the report, the current date is displayed in Mexican Spanish format.
Which code segment should you use?

A.
DateTimeFormatInfo dtfi = new CultureInfo(“es-MX”,false).DateTimeFormat;
DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
string dateString = dt.ToString(dtfi.LongDatePattern);

B.
Calender cal = new CultureInfo(“es-MX”,false).Calender;
DateTime dt = new DateTime(DateTime.Today.Year,DateTime.Today.Month,DateTime.Today.Day);
string dateString = dt.ToString();

C.
string dateString = DateTimeFormatInfo.CurrentInfo.GetMonthName(DateTime.Today.Month);

D.
string dateString = DateTime.Today.Month.ToString(“es-MX”)

Explanation:
Create a Mexican Spanish CultureInfo object. Convert the date to a string using the DateTimeFormatInfo returned by the CultureInfo object.
B does not use the CultureInfo object to convert the date to a string.
C does not use the Mexican Spanish culture.
D the DateTime.ToString() method cannot take a string code representation of the culture.



Leave a Reply 1

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


networkmanagers

networkmanagers

I have the same idea. A