Handlebars.Net.Helpers icon indicating copy to clipboard operation
Handlebars.Net.Helpers copied to clipboard

Add TImezone converters to DateTime helpers

Open match-fabianosuet opened this issue 3 months ago • 0 comments

As a tech, I'd like to add 2 new helpers to convert a certain Datetime to a specific timezone

Example: Convert straight from UTC:

DateTime utcTime = DateTime.UtcNow; // Or your existing UTC DateTime
DateTime targetTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, targetTimeZone);
return targetTime;

If your initial DateTime is in a different timezone (e.g., local time):

DateTime sourceTime = DateTime.Now; // Or your existing local DateTime
TimeZoneInfo sourceTimeZone = TimeZoneInfo.Local; // Or the appropriate TimeZoneInfo for your source
DateTime targetTime = TimeZoneInfo.ConvertTime(sourceTime, sourceTimeZone, targetTimeZone);
return targetTime;

As result this should generate a new Datetime with the calculated timezone.

match-fabianosuet avatar Oct 14 '25 16:10 match-fabianosuet