The most reliable way to generate a timestamp with Python

advertisements

I am wondering what the most reliable way to generate a timestamp is using Python. I want this value to be put into a MySQL database, and for other programming languages and programs to be able to parse this information and use it.

I imagine it is either datetime, or the time module, but I can't figure out which I'd use in this circumstance, nor the method.


For a database, your best bet is to store it in the database-native format, assuming its precision matches your needs. For a SQL database, the DATETIME type is appropriate.

EDIT: Or TIMESTAMP.