Creating a MySQL default date string from a Java Date

1

I need to pass a string in this format: "yyyy-mm-dd + HH: mm: ss" (where the "+" should be a space) for a webservice from a Java Date object. How can I do this?

    
asked by anonymous 28.03.2017 / 22:45

2 answers

0

You can do with SimpleDateFormat , but if you are passing the date to be formatted in "dd / MM / yyyy" mode and are trying to move to a webservice, SimpleDateFormat will not be able to format. I advise you to change the "/" to "-".

    
29.03.2017 / 02:27
1

You can use SimpleDateFormat to do this.

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String formatedDate = dateFormat.format( date );

You can read more about it here: link

    
28.03.2017 / 22:52