
Get unix seconds with Python
Notice: A non well formed numeric value encountered in /home/t00mlabs/blog.t00mlabs.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/t00mlabs/blog.t00mlabs.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Notice: A non well formed numeric value encountered in /home/t00mlabs/blog.t00mlabs.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/t00mlabs/blog.t00mlabs.net/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Get unix seconds:
1 2 3 4 5 6 7 8 9 10 11 |
import time from datetime import datetime before = datetime.now() after = datetime.now() s1 = time.mktime(now.timetuple()) s2 = time.mktime(now2.timetuple()) s2 - s1 |
Get datetime:
1 |
print(datetime.fromtimestamp(int(s1)).strftime('%Y-%m-%d %H:%M:%S')) |