0

I know how to get time of the current day in seconds

import time seconds=time.time() % 86400 

However the result is valid for UTC. Is there elegant way to do that for local time? I am aware I could get that somehow from local time struct_time, but it will be rather complicated procedure. Is there any elegant way to do that?

8
  • Add the timezone offset to time.time() before getting the modulus. Commented Sep 19, 2019 at 16:55
  • Perhaps you could look at this answer: stackoverflow.com/a/15971505/8935887 Commented Sep 19, 2019 at 16:55
  • Can you post some example so that the answer is specific to the problem statement. Commented Sep 19, 2019 at 16:55
  • @Barmar The problem is that offset is changing due to summer saving time. Commented Sep 19, 2019 at 16:56
  • @BrianTon It is using datetime and is rather awkward. Commented Sep 19, 2019 at 16:59

1 Answer 1

1

It's not complicated to get it from struct_time.

t = time.localtime() secs = 3600 * t.tm_hour + 60 * t.tm_min + t.tm_sec 
Sign up to request clarification or add additional context in comments.

4 Comments

I guess this is less complicated than stackoverflow.com/questions/19289016/…
I expected there should be something simpler and seconds are rounded to integer.
If you want the fraction you can add math.modf(time.time())[0]
Or perhaps add time.time() % 1?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.