Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add TimeZone to DateTime.UtcNow?

Tags:

c#

datetime

I have a TimeZone received from customer and I use it to set expiration DateTime so that it is UTC equivalent of "End of Month" in customer's time zone.

I tried this:

var current = timezone.ToUniversalTime(DateTime.UtcNow);

But could not manage to work. Can anybody help me with that?

like image 870
Jake Manet Avatar asked Dec 02 '25 20:12

Jake Manet


1 Answers

You can try like this:

DateTime utcTime = new DateTime(2016,2,10,10,15,00);
var tz = TimeZoneInfo.FindSystemTimeZoneById("Your Time Zone");
var tzTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, tz);
//To get time in UTC
var utcTime = TimeZoneInfo.ConvertTimeToUtc(tzTime, tz);
like image 194
Rahul Tripathi Avatar answered Dec 04 '25 10:12

Rahul Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!