How to get the time of specific timezone using C#,?

Good Day

I need to determine the time (DateTime object) in the Australian Western Standard Time regardless what the user's local time zone is set time zone can be anything i will pass in log out date time and then when the user logs in he will get the log out time of his country standard time and not the server time

so how do i achieve this :) using offset

TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(Convert.ToString("Australian Western Standard Time"));

  DateTime yourESTTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, tst);
Jon Skeet
people
quotationmark

It's not really clear what you're trying to achieve, but if you just want to get the current time in a particular time zone, you can use:

// No need to call Convert.ToString - it's already a string!
string zoneId = "W. Australia Standard Time";
TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
DateTime australianNow = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zone);

You might want to consider using DateTimeOffset instead of DateTime, by the way - you can always get a DateTime from that, but it means you have the offset if you ever need it.

You might also want to consider using my Noda Time library, which splits up "local time", "a point in time in a time zone" etc rather more clearly, IMO. You'd use:

// You'd normally inject this instead, so that you can use a fake clock for
// testing
IClock clock = SystemClock.Instance;

// Or you could use the TZDB provider, with the appropriate time zone ID
var zone = DateTimeZoneProviders.Bcl["Australian Western Standard Time"];

// What is the current time in the given time zone? The result retains the
// time zone as well as the instant in time, but properties like Hour return
// the *local* time in that time zone.
var zonedDateTime = clock.Now.InZone(zone);

// You may not need this at all - it depends on what you want to do
var localDateTime = zonedDateTime.LocalDateTime;

people

See more on this question at Stackoverflow