|
-
Aug 15th, 2007, 10:09 AM
#1
Thread Starter
Lively Member
[2.0] Formating DateTime
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.
-
Aug 15th, 2007, 02:33 PM
#2
Lively Member
Re: [2.0] Formating DateTime
I am not sure about the year. However, I would think you could use the padleft command to format that year.
-
Aug 15th, 2007, 06:18 PM
#3
Fanatic Member
Re: [2.0] Formating DateTime
-
Aug 15th, 2007, 06:46 PM
#4
Re: [2.0] Formating DateTime
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 or custom format strings 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|