Date comparisons in different formats
I am trying to compare dates sent to MySQL in ISO 8601 compliant format, i.e. "2018-12-31T12:59:59Z" that are retrieved from the dB column as "2018-12-31 12:59:59.0" using Groovy; however, I don't know how, or which date, I should convert to do the comparison.
Any suggestions would be greatly appreciated.
Thanks in advance!
One way you can achieve this is through java's simpleDateFormat:
import java.text.SimpleDateFormat def sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'") def timeCheck = sdf.format(<java.util.Date object>)
this sdf will put your Date object (30/07/2018 14:57:14.219) in the form 2018-07-30T14:57:14.219Z and this result is a string (you would pass the date object pulled from the db to the formatter)
hopefully this is what you wanted,
Mo
EDIT: it seems you do not want the milliseconds, so your sdf should be
def sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- MoUddin's answer should do it. If you still didn't manage it though we'll help you further.
Not sure if you received my thank you on the email feed, so wanted to thank you again here, Mo.
Your suggestion was EXACTLY what I needed - thanks again!
Apologies if lots of duplicates are being posted - I am new to all this community/posting processes. Thanks, your suggestion worked for me!