Search code examples
javascriptc#datetimeutctoisostring

C# Datetime conversion with the same operation of javascript


Good morning, I have this string format "1444050466000" and if I use javascript I can convert it in a value type date.

Example:

var b = "1444050466000";
var isoDate = new Date(b).toISOString('yyyy-MM-dd HH:mm:ss Z');

result: 2015-10-05T13:07:46.000Z

My question is, there is a way to do the same conversion in C#?


Solution

  • You could create a base DateTime representing a Unix Timestamp (1.1.1970 UTC) and add the milliseconds: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(1444050466000)