I am confused about using datetimes in databases and applications for international users. My application is developed asp.net web api and c# programming language.
I am using a column in database (postgresql) named created_at that type is without timezone.
When New York Time 2020-11-02 23:50:00, London Time is 2020-11-03 04:50:00. So day and hour is different.
And I want to show dates in relative time like Now, 1 Hours ago, 10 minutes ago...
If Someone adds a record in database at 2020-11-03 04:50:00 in London, someone shows the record as relative time 5 hours after. This looks a little strange.
Is this a true logic? How does it workin real applications?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You could store your datetime as UTC and convert it to the users time zone correspondingly.
Or you could store your values in postgreSQL via its designated time types.
(see https://www.postgresql.org/docs/9.1/datatype-datetime.html)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0