Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

Python time.time in string

$
0
0

I want only the first part of a unix timestamp in this format

1714197412.2837634

I want only the numbers before the ".", or just 1714197412.

My script is importing "time" and I try this first:

print(int(time.time()))

which gives me the expected

1714197412

However when calling the function within my construction of a json payload like this:

def setpayload_bids_single(hps_id, pp_id):myjson = {"hpsId": hps_id,"powerPlantId": pp_id,"readPeriod": [        int(time.time()),        1714132800    ],"timeAxis": {"t0": int(time.time()),"dt": 900,"n": 200    }}return myjson

it complains that it has to be a string.

Changing to

print(str(time.time()))

results in the "longer" string

1714197412.2837634

How can I chop of everything after, and including the "." using the str function?


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>