converting a calendar object into a string in java with format “yyyy-mm-dd hh:mm:ss”

后端 未结 2 1456
故里飘歌
故里飘歌 2021-01-12 10:58

I\'m converting a date stored in a calendar object in a string for a query in MySQL. I need the string in format \"yyyy-MM-dd HH:mm:ss\", i.e.: \"2010-01-01 15:30:00\". I\'m

2条回答
  •  甜味超标
    2021-01-12 11:44

    It's just that months start from 0 (not 1)

    That said, you should not convert to string in order to insert a date in the DB. You can either use the timestamp, or java.sql.Date together with PreparedStatement

提交回复
热议问题