Hello,
i'm newest on Python, i want to convert this value 2014-08-14 16:35:38.159891 to this value 2014-08-14 16:35:38, i mean that i want that the format of the date like the following
aaaa-mm-dd hh:mm:ss
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
This is what we can do with the datetime and time modules in Python
import time
import datetime
print "Time in seconds since the epoch: %s" %time.time()
print "Current date and time: " , datetime.datetime.now()
print "Or like this: " ,datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
print "Current year: ", datetime.date.today().strftime("%Y")
print "Month of year: ", datetime.date.today().strftime("%B")
print "Week number of the year: ", datetime.date.today().strftime("%W")
print "Weekday of the week: ", datetime.date.today().strftime("%w")
print "Day of year: ", datetime.date.today().strftime("%j")
print "Day of the month : ", datetime.date.today().strftime("%d")
print "Day of week: ", datetime.date.today().strftime("%A")
That will print out something like this:
Time in seconds since the epoch: 1349271346.46
Current date and time: 2012-10-03 15:35:46.461491
Or like this: 12-10-03-15-35
Current year: 2012
Month of year: October
Week number of the year: 40
Weekday of the week: 3
Day of year: 277
Day of the month : 03
Day of week: Wednesday
Try:
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Try: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") I think is wha you want...
Question: And if I want to find the difference between two dates (Fields from the "project.task" model such as "repeat_until" and "date_deadline", because subtracting the two dates doesn't work and using .days doesn't work either.
thanks
Thanx David for your answer your answer but i want that Current date and time takes only this value, 2012-10-03 15:35:46
from datetime import datetime
current_date=str(datetime.now().date())
d2=datetime.strptime(current_date, "%Y-%m-%d")
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
8
5月 23
|
60270 | ||
|
0
3月 25
|
494 | ||
|
4
4月 24
|
172899 | ||
|
0
12月 23
|
1493 | ||
|
5
2月 25
|
224517 |