from datetime import datetime
import datetime
now = datetime.now()
now.month
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)
I cant find my fault. Can someone tell me the bug? It dosent work.
from datetime import datetime
import datetime
now = datetime.now()
now.month
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)
I cant find my fault. Can someone tell me the bug? It dosent work.
Are you trying to create timestamp?
In the print part you must use ()
You need to import strftime() to get the actual data and declare the variables in the correct format. ('%d/%m/%Y/%H/%M/%S') and declare timetupple() to make the ts. #Day,Month[with minuscule 'm' to represent the month],Year,Hour,Minutes,Seconds.
You will get a .float string something like ('37136381293.0') Then you need to regex the '.0' part. and convert it to INT via 'int()'.. User mktime with your date time and the date time that you need to create.
Thanks in advanced.
import time,datetime
from time import strftime
p = strftime('%d/%m/%Y/%H/%M/%S')
i5 = str((time.mktime(datetime.datetime.strptime(p,'%d/%m/%Y/%H/%M/%S').timetuple())))
i1 = '\d*'
i2 = re.compile(i1)
i3 = re.findall(i2,i5)
i4 = i3[0]
The problem in your code is with the import statements. I am assuming you are using Python 2, due to the lack of parentheses in your print statement. The two imports you are using conflict with each other because they have the same name, so python uses the one most recently imported.
You just need to put "from datetime import datetime" after "import datetime", remove "import datetime", or change
"now = datetime.now()" into "now = datetime.datetime.now()" and possibly remove "from datetime import datetime".
Last edited by YT$W@Tgsef354; 07-14-2016 at 06:34 AM.