发送电​​子邮件的用户的本地时间邮件、时间、用户

2023-09-06 10:12:50 作者:人生不过梦一场

我写,需要每隔一小时发封邮件在小时的节目,但同时本地用户。

I am writing a program that needs to send out an email every hour on the hour, but at a time local to the user.

说我有2个用户在不同的时区。约翰在纽约和弗雷德是在洛杉矶。服务器是在芝加哥。如果我想在下午6点地方给每个用户发送一封电子邮件,我不得不发送电子邮件给John在下午7点服务器的时间和弗雷德于16:00服务器时间。

Say I have 2 users in different time zones. John is in New York and Fred is in Los Angeles. The server is in Chicago. If I want to send an email at 6 PM local to each user, I'd have to send the email to John at 7 PM Server time and Fred at 4 PM Server time.

什么是一个好方法这.NET / SQL服务器?我发现所有的时区信息的XML文件,所以我正在考虑写一个脚本,将其导入到数据库中,它然后查询了。

What's a good approach to this in .NET / Sql Server? I have found an xml file with all of the time zone information, so I am considering writing a script to import it into the database, then querying off of it.

编辑:我用t4znet.dll,并做了所有的比较在.NET端

I used "t4znet.dll" and did all comparisons on the .NET side.

推荐答案

您有两种选择:

储存调整时间的邮件操作到数据库中的每个用户。然后,只需比较与存储时间服务器的时间。为了避免混淆和便携性的问题,我将存储任何时候UTC。因此,发送邮件时,服务器的 UTC 的时间()== storedUtcTime。 存储在本地时间为每个邮件操作到数据库中,然后将其转换上的动态。发送邮件时,服务器的 UTC 的时间()==来的 UTC 的时间(storedLocalTime,userTimeZone)。 Store the adjusted time for the mail action into the database for each user. Then just compare server time with stored time. To avoid confusion and portability issues, I would store all times in UTC. So, send mail when SERVERUTCTIME() == storedUtcTime. Store the local time for each mail action into the database, then convert on-the-fly. Send mail when SERVERUTCTIME() == TOUTCTIME(storedLocalTime, userTimeZone).

您应该决定是什么让最适合您的应用程序。例如,如果邮寄时间总是相同的所有用户,它更有意义去与选项(2)。如果事件发生时,甚至可以按用户的用户之间的变化,它可能使开发和调试容易,如果你选择选项(1)。无论哪种方式,你需要知道用户所在的时区。

You should decide what makes most sense for your application. For example if the mailing time is always the same for all users, it makes more sense to go with option (2). If the events times can change between users and even per user, it may make development and debugging easier if you choose option (1). Either way you will need to know the user's time zone.

*这些函数调用显然是假的,因为我不知道他们在T-SQL调用,但他们应该存在的。

*These function calls are obviously pseudo, since I don't know their invocations in T-SQL, but they should exist.