How to get Date object from json Response in typescript

前端 未结 4 2199
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 11:18

Here is my json:

{
  \"data\": [
    {
      \"comment\": \"3541\",
      \"datetime\": \"2016-01-01\"
    }
  ]
}

Here is model:



        
4条回答
  •  天命终不由人
    2020-11-28 11:42

    There is no way to know for TS/JS that this value is a date. It's a string and treated as such. Other data types are distinguishable but JSON doesn't provide any special support for date. You need to convert it manually.

    See for example this discussion how to transport and convert a date using JSON How do I format a Microsoft JSON date?

提交回复
热议问题