Reputation: 19
Hi i have some table with starttime end time and timezone
I get data in DateTime.Utc
And how i can check if the date what comes is get caught in this timezome from DB and this day
0-Monday... 5-Friday
If we have 0-1 this means start time in 23:00 Sunday to 22:00 Monday
public static DateTime GetDateTimeWithExchangeTimeZoneSessionStart(DateTime tickDateTime, string exchangeTimeZone)
{
DateTime convertedDateTime = tickDateTime;
switch (exchangeTimeZone)
{
case "5.5":
convertedDateTime = convertedDateTime.AddHours(-5.5);
break;
case "4":
convertedDateTime = convertedDateTime.AddHours(-4);
break;
case "-6":
convertedDateTime = convertedDateTime.AddHours(6).AddDays(-1);
break;
case "0":
break;
}
return convertedDateTime;
}
But it's not good i think
Upvotes: 0
Views: 133
Reputation: 19
i need check if the date what come - is in this days from DB How it's will be code with dateofday method and this data 0,1,2,3,4,5,6
maybe write some class with this sessionstart sessionend and settlementime fields - and check this in utc0 and this time 17:00 etc.
Upvotes: 0
Reputation: 1500165
Firstly, it's important to understand that what you've got isn't a time zone. It's a UTC offset (although the negation of what it would normally be...). A real time zone would need to indicate how that UTC offset varies over time (e.g. due to daylight saving time changes).
However, with the data you've got, it looks like all you need is:
double hours = double.Parse(exchangeTimeZone, CultureInfo.InvariantCulture);
TimeSpan offset = TimeSpan.FromHours(hours);
return tickDateTime - offset;
However:
DateTimeOffset
given that you really do have a DateTime
and an offsetDateTime.Kind
... basically, DateTime
is somewhat broken. Upvotes: 1