I have json string like "1536476400000" and i convert into "yyyy-MM-dd" format using C#. please help me
Asked
Active
Viewed 489 times
-1
-
is 1536476400000 a timestamp in milliseconds? – Leandro Keen Zapa Sep 10 '18 at 04:57
-
i don't know which format just its json response and it convert into online it will display date – Software Engineer Sep 10 '18 at 04:58
-
well i already tried it. And its a timestamp in millisecond dated sept. 9 2018. refer to this topic. it might help you. https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa – Leandro Keen Zapa Sep 10 '18 at 05:00
-
Possible duplicate of [How can I convert a Unix timestamp to DateTime and vice versa?](https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa) – Mojtaba Tajik Sep 10 '18 at 05:01
-
@John i test it using https://www.epochconverter.com, no problem and it's the time for yesterday. – Mojtaba Tajik Sep 10 '18 at 05:04
-
Thanks to all, i got solution.. Thanks you all again... – Software Engineer Sep 10 '18 at 05:04
2 Answers
5
Solved Answer is...
String offset = "1536476400000";
double spotQuoteEffDate = double.Parse(offset );
TimeSpan spotQuoteEffDateTime = TimeSpan.FromMilliseconds(spotQuoteEffDate);
DateTime spotQuote = new DateTime(1970, 1, 1) + spotQuoteEffDateTime;
Output is...
spotQuote = 9/9/2018 7:00:00 AM

Software Engineer
- 290
- 1
- 3
- 14
2
Please refer below code,
TimeSpan s = TimeSpan.FromMilliseconds(double.Parse("1536476400000" ));
DateTime dt = new DateTime(1970, 1, 1) + s;
Console.writeline(String.Format("{0:yyyy-MM-dd}",dt));

Anup Patil
- 209
- 2
- 19