Angular UI DatePicker adjusting for timezone

前端 未结 6 602
忘了有多久
忘了有多久 2020-12-08 04:19

I have a date stored as a Date in SQL Server. The date shows 4/24/2014 when I query in SQL. That is correct. The date is correctly brought over to the client side in UTC. To

6条回答
  •  Happy的楠姐
    2020-12-08 04:42

    I had a very similar problem a while ago: I wanted to store local dates on the server side (i.e. just yyyy-mm-dd and no timezome/time information) but since the Angular Bootstrap Datepicker uses the JavaScript Date object this was not possible (it serializes to a UTC datetime string in the JSON as you found out yourself).

    I solved the problem with this directive: https://gist.github.com/weberste/354a3f0a9ea58e0ea0de

    Essentially, I'm reformatting the value whenever a date is selected on the datepicker (this value, a yyyy-mm-dd formatted string, will be stored on the model) and whenever the model is accessed to populate the view, I need to wrap it in a Date object again so datepicker handles it properly.

提交回复
热议问题