Which code segment should you use?

You are developing an application that accepts the input of dates from the user.
Users enter the date in their local format. The date entered by the user is stored in a string variable
named inputDate. The valid date value must be placed in a DateTime variable named validatedDate.
You need to validate the entered date and convert it to Coordinated Universal Time (UTC). The code
must not cause an exception to be thrown.
Which code segment should you use?

You are developing an application that accepts the input of dates from the user.
Users enter the date in their local format. The date entered by the user is stored in a string variable
named inputDate. The valid date value must be placed in a DateTime variable named validatedDate.
You need to validate the entered date and convert it to Coordinated Universal Time (UTC). The code
must not cause an exception to be thrown.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
AdjustToUniversal parses s and, if necessary, converts it to UTC.
Note: The DateTime.TryParse method converts the specified string representation of a date and time
to its DateTime equivalent using the specified culture-specific format information and formatting
style, and returns a value that indicates whether the conversion succeeded.



Leave a Reply 3

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


Jun Yang

Jun Yang

AssumeLocal
If no time zone is specified in the parsed string, the string is assumed to denote a local time.

Lord Vader

Lord Vader

DateTimeStyles Enumeration
AssumeLocal
If no time zone is specified in the parsed string, the string is assumed to denote a local time.

AdjustToUniversal
Date and time are returned as a Coordinated Universal Time (UTC). If the input string denotes a local time, through a time zone specifier or AssumeLocal, the date and time are converted from the local time to UTC.