简体   繁体   中英

How does wok relative time in different time zones?

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?

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM