I
I
iamserge2020-08-22 05:46:10
C++ / C#
iamserge, 2020-08-22 05:46:10

How to create DateTime with TimeZoneInfo without changing the time?

Everything seems to be simple. I have "New Zealand Standard Time", well, I have the time of the event as 15:00... That is, at this time in this time zone, the event occurs. Then it needs to be converted at different times.

I want to convert like this "TimeZoneInfo.ConvertTime", but how easy it is to create a DateTime object and a specific time zone???

I tried this, but how to proceed further and simply add this New Zealand and its time zone without time conversion, I can’t understand in any way ...

DateTime UnspecifiedDateTime = DateTime.SpecifyKind(new DateTime(2020, 08, 22, 15, 00, 0), DateTimeKind.Unspecified);


How do I adjust my "New Zealand Standard Time" now to a ready time and date? It just seemed like the simplest task and I thought that when creating everything would be without problems one way or another ...

But no, now any attempts to somehow attach "New Zealand Standard Time" without conversion end up with a conversion and time ... I tried to find a method TimeZoneInfo or DateTime, but there is nothing like that there either ...

How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-08-22
@iamserge

If so

DateTime UnspecifiedDateTime = DateTime.SpecifyKind(new DateTime(2020, 08, 22, 15, 00, 0), DateTimeKind.Unspecified);
var nzstTz = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
var mskTz = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
var mskTime = TimeZoneInfo.ConvertTime(UnspecifiedDateTime, nzstTz, mskTz);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question