2

I am getting data back from server like 2020-02-17 15:36:47 (with no time zone descriptor). This is a date that is generated BY the server and is actually in UTC time (the server's "local" time). However, it is stored as DateTime in MySQL without time zone information.

When I get this back from the server, I need to convert it to local time, but when I try to apply date pipe like dateVariable | date: 'short' : 'UTC' it actually adds time rather than takes it away (my local time is EST) - so I get 2/17/20, 8:36 PM where it should actually be 2/17/20, 10:36 AM.

I guess ths issue is that the client assumes the time coming from the server is already local time, and my pipe is converting it to UTC. In fact, I want to do the opposite - the server time is stored as UTC (even though it is not indicated as such in MySQL DateTime column), and I want to convert to EST (local) using the date pipe. I've searched about and not sure how to handle this outside of modifying what the server returns.

QuietSeditionist
  • 703
  • 4
  • 8
  • 18
  • take the date and time and add your timezone in js. the mysql server timezone you can get so https://stackoverflow.com/a/2934271/5193536 – nbk Feb 19 '20 at 22:50
  • I don't have an absolute tested suggestion for you, but I don't think datePipe by itself will do what you want. I would suggest looking at moment-timezone. I haven't tried it, but I think something like moment.tz(dateVariable, "UTC") should get you close... [Play around, it took me a while to find the combinations that worked for my needs.] – Bill Turner Apr 15 '20 at 20:14

0 Answers0