I want to convert:
5/25/2010 12:54:56:000
to:
05252010125456000
How do I do that in C#?
How do you convert datetime to milliseconds? A simple solution is to get the timedelta object by finding the difference of the given datetime with Epoch time, i.e., midnight 1 January 1970. To obtain time in milliseconds, you can use the timedelta. total_seconds() * 1000 .
To display the millisecond component of a DateTime value If you're working with the string representation of a date, convert it to a DateTime or a DateTimeOffset value by using the static DateTime. Parse(String) or DateTimeOffset. Parse(String) method.
Millis is the popular abbreviation for milliseconds. The formal one would be ms.
The ToString() method of the DateTime class is used to convert a DateTime date object to string format. The method takes a date format string that specifies the required string representation.
You can use a custom format string. Example:
string formatted = DateTime.Now.ToString("MMddyyyyHHmmssfff");
Try this:
DateTime.Now.ToString("HH:mm:ss.ffffff");
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With