-2

enter image description here

can somebody help me? I tried everything!

Nate
  • 9
  • 1
  • 8
  • are you using mono? – fubo Dec 17 '19 at 08:05
  • https://stackoverflow.com/questions/7908343/list-of-timezone-ids-for-use-with-findtimezonebyid-in-c I don't see Asia/Jerusalem in this list. Are you sure its called that? – EpicKip Dec 17 '19 at 08:06
  • TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, "Asia/Jerusalem"); this line worked on my co-worker computer – Nate Dec 17 '19 at 08:07
  • yes I'm using mono – Nate Dec 17 '19 at 08:10
  • @Nate https://learn.microsoft.com/en-us/dotnet/api/system.timezoneinfo.id?view=netframework-4.8#System_TimeZoneInfo_Id use this to print all timezones you have. – EpicKip Dec 17 '19 at 08:10
  • Which operating system are you using, and which operating system is your co-worker using? – Jon Skeet Dec 17 '19 at 08:15
  • I printed I didn't see Jerusalem but I saw Israel – Nate Dec 17 '19 at 08:16
  • we both use the newest Windows – Nate Dec 17 '19 at 08:16
  • @Nate: I'd be surprised to see that code working on Windows (when not under Windows Subsystem for Linux etc). – Jon Skeet Dec 17 '19 at 08:17
  • 1
    As an aside, it's unclear to me what that code is intended to achieve, but I'd definitely suggest using `DateTime.UtcNow` rather than `DateTime.Now` - there's no point in getting your system local time zone involved as well as the time zone you're trying to work with. – Jon Skeet Dec 17 '19 at 08:18
  • var dt = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Asia/Jerusalem"); still doesnt get anything – Nate Dec 17 '19 at 08:22
  • Sounds like you could use https://github.com/mj1856/TimeZoneConverter – Matt Johnson-Pint Dec 17 '19 at 15:28

2 Answers2

2

"Asia/Jerusalem" is an ID in the style used by the IANA time zone database (aka tzdb or tz or zoneinfo). Windows uses its own time zone IDs which are very different.

If you want to use IANA time zones in a cross-platform way, I'd suggest using the Noda Time project which I maintain, instead of TimeZoneInfo.

Additionally, values such as "number of seconds since the epoch" are normally not time-zone-sensitive; the Unix epoch is fixed at 1970-01-01T00:00:00 UTC, not "midnight on January 1st 1970 local time on a per time zone basis". While such a value can be useful (we have the concept internally in Noda Time) I would think very carefully before using that. Ideally, stick to a higher level abstraction - in Noda Time, I'd suggest using ZonedDateTime, Instant or LocalDateTime, depending on your requirements.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
-1

I will look it up, but I am guessing it calls or uses the same data as TimeZoneInfo.GetSystemTimeZones(). As the name implies, not all Timezones are avalible on all computers.

Edit: I could confirm it. GetSystemTimeZones is actually returns a ReadonlyCollection, Built from the Registry with some Caching. And if I read it right, it will not exist at all (Conditional Compilation) if you do not have the FEATURE_WIN32_REGISTRY Flag set. FindSystemTimeZoneById() has the same rules and limitations, and indeed accesses the same cache.

.NET in general tries to use the timezone rules and conversions that the Operating System has. So it is quite possible this Timezone does not exist, or is there under another name. And here it seems to be limited 100% to what the Windows Registery says.

Christopher
  • 9,634
  • 2
  • 17
  • 31