I
I
ivanburdin2018-02-15 17:53:43
Python
ivanburdin, 2018-02-15 17:53:43

How to get the current moment of a date in a random timezone?

Good afternoon!
Piece of code:

delta = 0
t = datetime.now() + timedelta(seconds=delta)
'%s+03:00' % t.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3]

Returns:
'2018-02-15T15:49:22.413+03:00'
this is the value of the current date.
I wondered how to get the date and time value at the current moment, but in some random time zone? +-12 hours

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2018-02-16
@ivanburdin

import pytz

tz = pytz.timezone('Europe/Berlin')
berlin_now = datetime.now(tz)

C
chupasaurus, 2018-02-15
@chupasaurus

There datetime.timedeltaare hours and minutes parameters .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question