| | |
convert from one timeformat to another
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 14
Reputation:
Solved Threads: 0
Hi all
I want to create a method that converts from one time or date format (as a string) to another by specifying the inputformat and the outputformat. I can do the output as below but I'm struggling on how to specify what the input format is. Can anyone help?
thanks.
I want to create a method that converts from one time or date format (as a string) to another by specifying the inputformat and the outputformat. I can do the output as below but I'm struggling on how to specify what the input format is. Can anyone help?
thanks.
C# Syntax (Toggle Plain Text)
//I'm halfway there. string date = FormatDateTime(myDate, "yyyyMMdd")); string time = FormatDateTime(myTime, "HHmm")); private string FormatDateTime(string dateortime, string outputformat) { string ret = ""; if (dateortime == "") return ""; try { ret = System.Convert.ToDateTime(dateortime).ToString(outputformat); } catch { } return ret; }
Use a DateTime to do it.
As an example look at this.
As an example look at this.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
Use DateTime.TryParseExact
•
•
•
•
SUMMARY:
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded.
![]() |
Similar Threads
- download pdf file, convert to html, in PHP since working in Linux (PHP)
- convert int to string (C)
- How to convert wav to mp3 using VB? (Visual Basic 4 / 5 / 6)
- cannot convert from 'double' to 'float [6][3]' (C)
- problem with convert jumbled text file to unjumbled text file (C)
- Need help to convert Int64 to Base36 ? (PHP)
- VC++:convert File IStream to hex and store...? (C++)
Other Threads in the C# Forum
- Previous Thread: Hello, need help with dates and select statement
- Next Thread: data string to array
| Thread Tools | Search this Thread |
Tag cloud for format, time
abrupt ada alarm bluray bmp c++ class click clock clocks code compile conversion convert css date datetime design digital drive dual dvd exam exe execution firefox format geek hd html ide image introduction introductory java jpeg lapse layer linux math news numbers partition professor proficiency program py py2exe python reference retrieve running save schedule sony sort source string studio test time timespan tlapse tutorial university unix unreadable vb video vista visual war wxpython







