import datetime dt = datetime.datetime.now() print dt.year print dt.month print dt.day print dt.hour print dt.minute print dt.secondVery easy right ^^
Pages
Profile
|
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time.
Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more... |
Wednesday, December 1, 2010
How to get current Date/Time in Python
In my project, sometimes I have to used current date to compare. So, we need to get date from the system.
Labels:
Programming,
Python
Subscribe to:
Post Comments (Atom)
Also strftime is very handy:
ReplyDeletedatetime.datetime.today().strftime("%Y-%m-%d %H:%M")
Out[25]: '2011-09-05 03:57'
Oh, thanks a lot @marwal. I have never used string format in Python yet. And Can we adjust any format that we want to? or it's need to be standard time format?
ReplyDeleteIf I understand your question, yes.. you could format the parts of time and parts of date into whatever you'd need.
ReplyDeleteMaybe you can tell me something: Are teachers (Linux, Apache, PHP, Python, SQL) needed in Thailand or Laos? I would very much want to live and work in those countries.
In Thailand, yes, they are needed for Linux, Apache, and SQL. Most of computer science courses in Thailand do not include Python (usually Java).
ReplyDelete