In C# how can I convert Unix-style timestamp to yyyy-MM-ddThh:mm:ssZ?
Usually we display time in in 12 hour format hh:mm:aa format (e.g. 12:30 PM) or 24 hour format HH:mm (e.g. 13:30), however sometimes we also want to show the milliseconds in the time. To show the milliseconds in the time we include “SSS” in the pattern which displays the Milliseconds.
To convert a second measurement to a millisecond measurement, multiply the time by the conversion ratio. The time in milliseconds is equal to the seconds multiplied by 1,000.
Start by converting your milliseconds to a TimeSpan
:
var time = TimeSpan.FromMilliseconds(milliseconds);
Now, in .NET 4 you can call .ToString()
with a format string argument. See http://msdn.microsoft.com/en-us/library/system.timespan.tostring.aspx
In previous versions of .NET, you'll have to manually construct the formatted string from the TimeSpan's properties.
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