Don't work with date and time separately. From a certain point of view, there is no such thing as "date"; this is really just a sub-set of time points (range, programmers say, not quite correctly). In your case, the property
Date
is useless.
What you really need is time formatted using appropriate format specifier. See all the methods
System.DateTime.ToString
and format specifiers:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[
^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[
^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[
^].
Note that
IFormatProvider
is supported by
System.Globalization.CultureInfo
for the parameter of
System.DateTime.ToString(IFormatProvider)
, see
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[
^].
In your case, you can use
System.DateTime myTime = System.DateTime.Now;
string myTimeString = myTime.ToString("yyyy-MM-dd HH:mm:ss tt");
You did not explain what culture you need to apply for AM/PM, neutral or localized.
See the above references on how to have AM/PM localized, see the code sample:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#ttSpecifier[
^].
—SA