To convert a Samoa time to GMT in Python, we can make use of the datetime and timezone modules. The following code demonstrates this conversion:
main.py350 chars15 lines
In this code, we first create a datetime object for the input time in Samoa. We then use the pytz module to convert this object to a timezone-aware object in the 'Pacific/Samoa' timezone.
Next, we create a timezone object for GMT and use the astimezone() method to convert the input datetime to GMT. Finally, we print the output datetime object.
gistlibby LogSnag