Date format

Using the method I posted, one way would be to slice the res list to only include the elements that you want.

import time 
res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")

sRes = ''
for i in range(len(res[:3])):
	sRes += str(res[i])
	
print sRes
#results in 2014326

Using the method that @PGriffith posted, which admittedly is better and probably faster too:

import time 
res = time.strptime("Wed Mar 26 10:13:54 CET 2014", "%a %b %d %H:%M:%S %Z %Y")

print time.strftime("%Y%m%d",res)
#results in 20140326
1 Like