Skip to content

How to convert a time to the current timezone #2

@bsutton

Description

@bsutton

I have a datetime in gmt and need to print it out in the local timezone.

I thought I could do something like:

var gmtTime = DateTime.parse('2020-10-27 06:10:05+00:00');
var offset = DateTime.now().timeZoneOffset; /// this is a duration
dateTimeToOffset(datetime: expiryDate, offset: offset) // this is a double?

I'm really not a big fan of using doubles as the lack a unit.
Dart has really formalised Duration so I would expect this type of library to also use it.
The above impedance mismatch also causes problems.

The doco also doesn't state what unit the double is in. I'm guessing its hours?

I end up with:

var gmtTime = DateTime.parse('2020-10-27 06:10:05+00:00');
var offset = DateTime.now().timeZoneOffset; /// this is a duration
var hours = offset.inHours + offset.inMinutes / 60;
dateTimeToOffset(datetime: expiryDate, offset: hours) // this is a double?

But given the library is meant to make things easier ;<

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions