SqlAlchemy中的DateTimepython
from sqlalchemy import Column, String, DateTime from app import Base class User(Base): __tablename__ = 'user' id = Column(String(64), primary_key=True) create_time = Column(DateTime)
Python中的sql
import uuid import datetime from app.models import User from app import db_session @user_blueprint.route('/new') def new(): user = User() user.id = uuid.uuid4() user.create_time = datetime.datetime.now() db_session.add(user) db_session.commit() return success_resp()
時間轉換爲字符串session
user.create_time.strftime("%Y-%m-%d %H:%M:%S")