Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

java - Convert datatime and insert in MySQL

I have to import a CVS file containing 120k rows. The first 6 columns contain the date and time separately, ie: year, month, day, hour, minutes, seconds.

I imported them into Java:

int year = 2016
int month = 5
int day = 23
int hour = 15
int minutes = 57
int seconds = 22 

How can I convert this format to a format compatible with MySQL (DATETIME)?

I also have a GMT column, i.e. "GMT +0200". Can I convert this data too in a DATETIME?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way you could do this is to build your string in this format:

yyyy-MM-DD HH:mm:ss

Then insert it.

INSERT INTO yourtable VALUES('2016-05-23 15:57:22')


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...