String to Timestamp conversion difference error in Java [duplicate]

String to Timestamp conversion difference error in Java [duplicate]



This question already has an answer here:



I have the following value:
2018-01-16-18.56.57.300000



It is passed to the method parameter: "value".


private Timestamp getPossibleTimestampI(String value)

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss.SSS");
Date parsedDate;
Timestamp timestamp=null;
try
parsedDate = dateFormat.parse(value);
timestamp = new java.sql.Timestamp(parsedDate.getTime());
catch (ParseException e1)
e1.printStackTrace();


return timestamp;



I am getting a Timestamp object with the value of 2018-01-16 19:01:57.0, about 5 minutes more compared to the original string value.



Why is this happening, and how can I correct my conversion?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






How many minutes is 300000 milliseconds?

– Sotirios Delimanolis
Sep 17 '18 at 17:18


300000






You are using terrible old classes that were supplanted years ago by the java.time classes.

– Basil Bourque
Sep 17 '18 at 20:00






Tip: learn about standard ISO 8601 formats.

– Basil Bourque
Sep 17 '18 at 20:01






You shouldn’t be wanting a Timestamp at all. That class is outdated and filled with design problems. For saving into your database use an Instant or if circumstances dictate, a LocalDateTime.

– Ole V.V.
Sep 18 '18 at 11:35


Timestamp


Instant


LocalDateTime






Since an older JDK (like version 6 or 7) cannot parse your string, I suggest you use the backport of java.time, the ThreeTen Backport library, it can. Only you will have to use its DateTimeUtils.toTimestamp method for converting to a Timestamp for your database.

– Ole V.V.
Sep 19 '18 at 6:43


DateTimeUtils.toTimestamp


Timestamp




1 Answer
1



In Time 2018-01-16-18.56.57.300000, Your 300000 milliseconds are being converted to minutes


which is 300000/60000 = 5 minutes






and how can I correct my conversion?

– Sotirios Delimanolis
Sep 17 '18 at 17:32






Remove miliseconds before conversion.

– Aagam Jain
Sep 17 '18 at 17:42

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế