Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - LocalDateTime remove the milliseconds

I am working in java application where i am using the Java 8.

I have integrated the database(multiple database Oracle,Mysql,Postgres) and where in DB i string the created date.

the date format in DB is - 2015-07-29 16:23:28.143

I fetch this from DB and set in Localdatetime object

myObj.setCreated(rs.getTimestamp("created").toLocalDateTime());

So here the issue is i dont want to show/send the millisecond in the response. i want to show/send date like 2015-07-29 16:23:28

I tried the formatter but it fails as it giving string and i dont want change the LocalDateTime object to String as this going to cause major change in all Java application.So want to find the solution

Can anybody know any solution on this.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Truncate

You can drop anything less than seconds. Call LocalDateTime::truncatedTo.

ldt = ldt.truncatedTo(ChronoUnit.SECONDS);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...