Click to See Complete Forum and Search --> : [2.0] Formating DateTime
Bobbo70
Aug 15th, 2007, 10:09 AM
Hi All;
I just moved from log time developing with VB and I face some problems in some functions from VB to C# like formating the DateTime specially the Time from 12 hours to 24 hours or vice versa and formating the Year from 2 digits to 4 digits and vice versa. :ehh:
zdavis
Aug 15th, 2007, 02:33 PM
I am not sure about the year. However, I would think you could use the padleft command to format that year.
daimous
Aug 15th, 2007, 06:18 PM
This (http://msdn2.microsoft.com/en-us/library/az4se3k1(VS.71).aspx) might Be of Help.
jmcilhinney
Aug 15th, 2007, 06:46 PM
You can convert a DateTime to a string representation by calling its ToLongDateString, ToLongTimeString, ToShortDateString, ToShortTimeString or ToString methods. The first four will use the formats specified in the system's regional settings. The fourth will also use the standard format specified in regional settings if no parameter is specified. You can also specify a format string that conforms to any of the standard format strings (http://msdn2.microsoft.com/en-us/library/az4se3k1(vs.80).aspx) or custom format strings (http://msdn2.microsoft.com/en-us/library/8kb3ddd4(vs.80).aspx) for date and time values.
To convert strings to DateTimes you would use DateTime.Parse, ParseExact, TryParse or TryParseExact, depending on whether you were sure the values was valid and whether it used a standard format or not.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.