SoFunction
Updated on 2025-04-08

Problem using timestamp in python

Use timestamp in python

() in python is the time stamp

Code:

import time
time_stamp = ()
print(time_stamp)

time_array = (time_stamp)
other_way_time = ("%Y-%m-%d %H:%M:%S", time_array)
print(other_way_time)

result:

1610608539.8310502
2021-01-14 15:15:39

Of course, many timestamps will record integers, and int is required

import time
time_stamp = int(())
print(time_stamp)

result:

1610608841

Related applications based on timestamps

1. Get the current time

Get detailed time data such as the current year, month, day, hour, minute, and week, etc.

import time
print (('%Y-%m-%d-%H:%M:%S-%A',(t1)))

Parameter meaning

  • %y Double digit year representation (00-99)
  • %Y Four-digit year representation (000-9999)
  • %m Month (01-12)
  • %d One day in the month (0-31)
  • %H 24-hour hours (0-23)
  • %I 12-hour hours (01-12)
  • %M Minutes (00=59)
  • %S seconds (00-59)
  • %a Local simplified week name
  • %A Local full week name
  • %b Locally simplified month name
  • %B Local full month name
  • %c Local corresponding date and time representation
  • %j One day in the year (001-366)
  • %p local .or. equivalence
  • %U The number of weeks of the year (00-53) Sunday is the beginning of the week
  • %w Week (0-6), Sunday is the beginning of the week
  • %W The number of weeks of the year (00-53) Monday is the beginning of the week
  • %x local corresponding date
  • %X local corresponding time representation
  • %Z The name of the current time zone
  • %% % % number itself

2. Calculate the program running time

Enter the line before the program block

start_time=()

Enter one line after the program block

end_time=()
print ("Time to take %s seconds" % (t4-t3))

3. Conversion of timestamps

import time
#a=int(input())
t1=()
# Timestamp conversion date, etc.aa=('%Y-%m-%d-%H:%M:%S %A',(t1))
print (aa)
# Convert it to a time arraytimeArray = (aa, "%Y-%m-%d-%H:%M:%S %A")
print(timeArray)
# Convert to timestamp:timeStamp = float((timeArray))
print(timeStamp)

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.