Сравните даты разных часовых поясов в ASP.NET от DBC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Сравните даты разных часовых поясов в ASP.NET от DB

Сообщение Anonymous »

Код: Выделить всё

DateTime test = new DateTime(2025, 4, 9, 4, 0, 0); //instead of the it would be DateTime.UtcNow
TimeZoneInfo timeZoneInfo = getUserTimeZoneInfo(); //Converting to toronto time EDT going on
DateTime currentUserTime = ConvertToUserTimeZone(test, timeZoneInfo);
var result = (from message in dbContext.Messages
join userMap in otherContext.UserMessageMappings
.Where(u => u.UserEmail == currentUserEmail)
on message.Id equals userMap.MessageId into messageJoin
from userMapping in messageJoin.DefaultIfEmpty()
where message.IsDeleted == false
select new MessageDto
{
Id = message.Id,
FileName = message.FileName,
EffectiveDate = message.EffectiveDate,
ExpirationDate = message.ExpirationDate,
Title = message.Title,
Content = message.Content,
SecondaryTitle = message.SecondaryTitle,
SecondaryContent = message.SecondaryContent,
Region = message.Region,
CreatedBy = message.CreatedBy,
CreatedAt = message.CreatedAt
})
.AsEnumerable()
.Where(msg => msg.ExpirationDate.HasValue && msg.EffectiveDate.HasValue
currentUserTime = ConvertToUserTimeZone(msg.EffectiveDate.Value, timeZoneInfo))
.ToList();
In the database the ExpirationDate and EffectiveDate are stored like so

ExpirationDate: 2025-04-10 23:59:59.0000000

EffectiveDate: 2025-04-09 00:00:00.0000000

The time is the same for all messages В DB и дате, какой бы пользователь был установлен пользователем < /p>
В результате я хочу получить только те сообщения, которые истекают или становятся эффективными в ту же дату DateTime, что и в DB, ​​но в пользователях часовой часовой 23:59:59.0000000

EffectiveDate: 2025-04-09 00:00:00.0000000

The test is 2025-04-09 04:00:00.0000000

DateTime test = new DateTime (2025, 4, 9, 4, 0, 0);
< /p>
< /blockquote>
Таким образом, текущее время, предполагающее, что мы конвертируем в EDT, будет 2025-04-09 04: 00: 00.0000000 < /strong> < /p>

DateTimeRime = ConvertTousTime (blockquote>
dateTimeRime = ConvertToustime (BrockQuote>
DateTimeM Timezoneinfo);

Таким образом, эффективность и истекает, преобразованный в EDT, будет 2025-04-08 20: 00: 00.0000000
и 2025-04-10 19: 59: 59.0000000 2025-04-10 19: 59: 59,00000 2025-04-10 19: 59: 59.0000000 currentUserTime >= ConvertToUserTimeZone(msg.EffectiveDate.Value, timeZoneInfo) //returns true but

currentUserTime

Подробнее здесь: https://stackoverflow.com/questions/795 ... et-from-db
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»