比如:我的项目要往数据库中插入create_time和update_time,那就势必要引用现在的系统时间,经过大量的查找,终于发现往python是没有对应时间datetime的相关通配符的,那么我们要怎么实现呢。
其实很简单,我们只需要把datetime转换成字符串类型的就行
我的代码如下:
[java]
view plain
copy
def insertIntoChannel(self, user): conn = JDBCUtils.getConnection() cursor = conn.cursor() dt=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") cursor.execute("insert into user(id,age,name,create_time,update_time) \ values('%d','%d','%s','%s','%s')" % \ (user.getId(),user.getAge(), user.getName(),dt,dt)) cursor.close() conn.commit() conn.close()
具体实现就是这样,希望对大家有所帮助。