0

I am storing date and time separately from Angular to C#. While storing in database, I combine start date and start time field in C# and store it in dAtabase UTC like this: "2020-02-28T22:30:30Z". While returning from c#, i create a new DateTime with start date and start time and return as one variable. However, if the date is 28/02/2020 and time is 4.00 am, with timezoneoffset of 5.30 India, the date gets rendered to 29/02/2020 4.00 am. Is it possible to get date and time in Angular and render it separately as string etc.

Thanks

Gauravsa
  • 6,330
  • 2
  • 21
  • 30
  • 1
    Please include an [mcve] that illustrates your problem. It is not clear at the moment where your problem is or what it is based on the description alone. It should be easy to create an example using either pure javascript in the question or you can add the code here and create the example in https://stackblitz.com and include a link in the question. – Igor Feb 27 '20 at 19:19

2 Answers2

1

In JavaScript Date is a timestamp, counts the number of miliseconds since January 1, 1970 00:00 UTC. So you might be having a problem with timezones. Check this answer I gave a couple of weeks ago, it may guide you. I also add a function to solve it and some references there, Subtract day in conversion between Moment and LocalDate.

cabesuon
  • 4,860
  • 2
  • 15
  • 24
0

angular set timezone based on user browser timezone so you can change datetimes to another timezone. please read it How to convert Date in angular to another time zone

Mehrdad
  • 1,523
  • 9
  • 23