To convert GMT to Samoa time in Python, you can use the datetime module along with the pytz library to handle timezones.
First, you need to create a datetime object representing the time in GMT. You can do this with the datetime.utcnow()
function, which returns the current UTC time.
main.py84 chars5 lines
Output:
main.py37 chars2 lines
Next, you need to create a timezone object representing the Samoa timezone. You can do this with the pytz.timezone()
function, passing in the timezone identifier Pacific/Apia
.
main.py54 chars4 lines
Finally, you can convert the GMT time to Samoa time by using the astimezone()
method of the datetime object and passing in the Samoa timezone object.
main.py76 chars3 lines
Output:
main.py45 chars2 lines
The output shows the Samoa time, which is one hour ahead of GMT (as Samoa is at UTC+14).
So, the complete code to convert GMT to Samoa time in Python is:
main.py214 chars10 lines
gistlibby LogSnag