Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date/time for specific region?

How do I get DateTime.Now for specific region?

I'm trying to get the current date in a foreign country, I'm looking for an easy way to achieve this.

Note: I don't mind getting the value from an online server, I just don't want to spend too much dev-time for it.

like image 711
Shimmy Weitzhandler Avatar asked Dec 19 '25 06:12

Shimmy Weitzhandler


1 Answers

If you know the timezone you want, you can use the TimeZoneInfo class. First get the TimeZoneInfo object for your desired timezone, then convert current time to that timezone:

var timezone = TimeZoneInfo.FindSystemTimeZoneById("Central America Standard Time");
var dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timezone);
like image 129
Adam Lear Avatar answered Dec 21 '25 20:12

Adam Lear



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!