Skip to content

Add TImezone converters to DateTime helpers #134

Description

@match-fabianosuet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions