如何在不同时区用户的数据库中保留时间

编程入门 行业动态 更新时间:2024-10-25 15:24:53
本文介绍了如何在不同时区用户的数据库中保留时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个在server.User中运行的应用程序使用它来自不同的时区。现在我必须节省插入数据的时间。 当用户将数据保存在数据库中我正在做datetime.utcNow()。我认为它将服务器的本地时间(我的应用程序所在的位置)转换为utc时间。我是对的吗? 现在我已经保存了所有用户创建帐户的时区。现在我正在显示他们保存数据的时间(这是在utc的数据库中) )从utc转换到他们当地的时区(从我的帐户中取出他的时区)。 我是否正确?请帮助,实际上如果我是正确的,然后我将这个方法应用于整个项目。

I have an application running in server.User using this are from different time zone.Now I have to save the time of their inserted data. When user save the data in database I am doing datetime.utcNow().I think it converts the local time of server(in which my application is situated) to utc time. Am I right? Now I have saved all users' time zone on creating there account.Now I am showing their time of saved data (which is in database in utc) by converting from utc to their local time zone (from his account I'm fetching his time zone). Am I in right way?please help,actually if I am in right way then I'll apply this approach to the whole project.

推荐答案

如果您使用服务器时区作为转换的基础到UTC,这是一个基于网络的产品,然后不,这是不对的。您需要使用用户时区,并对此进行更正 - 他可能与您的服务器处于不同的时区(我是:我住在英国,我的网站服务器位于美国)。 这应该有所帮助: msdn.microsoft /en-us/library/bb882561(v=vs.110).aspx [ ^ ] - 它讨论了解决问题的几种方法。 If you are using the server time zone as the "Base" for your conversion to UTC and this is a web-based product, then no, it's not right. You need to use the user time zone, and correct for that - he may well be in a different time zone from your server (I am: I live in the UK, and my website server is in the USA). This should help: msdn.microsoft/en-us/library/bb882561(v=vs.110).aspx[^] - it discusses a couple of approaches to the problem.

更多推荐

如何在不同时区用户的数据库中保留时间

本文发布于:2023-10-17 10:49:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   时区   时间   用户   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!