0
from datetime import datetime
from time import time

print(f'{datetime.now()} and {time()}')

Yield 2022-03-25 16:27:37.051854 and 1648193257.051854
I hope to getdatetime.now() from time().

I found Sec: 37 = 1648193257 % 60.
27469887 = 1648193257 // 60
min: 27 = 27469887 % 60

But I could not find how can yield hour data and so on.

Yong
  • 35
  • 1
  • 5

2 Answers2

1

You can use the datetime.datetime.fromtimestamp() function for it.

print(datetime.datetime.now())
now = time.time()
print(now)
print(datetime.datetime.fromtimestamp(now))

Yields

2022-03-25 09:13:42.665469
1648196022.6654692
2022-03-25 09:13:42.665469

A similar question with answers you can find here

Doluk
  • 476
  • 2
  • 9
0

I recommend that you review this documentation

As an example, you can get the current hour as follows:

import time

print(time.localtime().tm_hour)
DarkKnight
  • 19,739
  • 3
  • 6
  • 22