datetime.now(timezone.utc) datetime.now(timezone.utc).timestamp() * 1000 # POSIX timestamp in milliseconds For your purposes when you need to calculate an amount of time spent between two dates all that you need is to subtract end and start dates. The results of such subtraction is a timedelta object. From the python docs:
I feel neccessary to add comment about "why" exactly this behaviour was implemented the way it was - it's because Postgresql doesn't actually store timezone even in "timestamp with timezone" type - it just assumes that input time is in UTC. So it's really easy to "shoot off your leg" in this one, especially when you use something like DateTime.Now More on that here - stackoverflow.com ...
I am currently using: sample_start_time AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time' AS sample_start_time_est from: Convert Datetime column from UTC to local time in select statement
How to convert from UTC to EST in SQL? - Stack Overflow
I have a column of the TIMESTAMP WITHOUT TIME ZONE type and would like to have that default to the current time in UTC. Getting the current time in UTC is easy: postgres=# select now() at time zon...
We have a column LAST_FINISH_ENTRY of type DATE holding values for the America/New_York timezone. We need to convert these to UTC in a new column LAST FINISH_ENTRY_DATE_UTC with type TIMESTAMP. I b...
As other answers point out, the UTC date string with Z designator would indeed be successfully parsed, but it would also be converted to local time, i.e. it returns DateTime with a Kind of Local and adjusted timestamp. To always get UTC DateTime, one could use one of DateTime.Parse("2008-01-01 00:00:00Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles ...