How to get Date object from json Response in typescript

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

Here is my json:

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

Here is model:



        
4条回答
  •  被撕碎了的回忆
    2020-11-28 11:48

    You can achieve it using 2 properties: a string property (say dateStr) for passing the date and a Date property (say dateVal) to hold the data object after conversion.

    Then in your constructor, you can simply do something like dateVal = new Date(dateStr).

提交回复
热议问题